Beginners: please read this post and this post before posting to the forum.
0 Members and 1 Guest are viewing this topic.
steeringWheelInput = Serial.read(); steeringWheelInput = constrain(steeringWheelInput, pot1Min, pot1Max);targetPosition = map(steeringWheelInput, pot1Min, pot1Max, -100, 100); wheelsInput = analogRead(A0);wheelsInput = constrain(wheelsInput, pot2Min, pot2Max);currentPosition = map(wheelsInput, pot2Min, pot2Max, -100, 100);error = targetPosition - currentPosition;if (error > 10) { turn = Kp * error; turn = constrain(turn, -63, 63); turn = turn + 64; (send turn to Roboclaw) }
#include <SoftwareSerial.h>//RECEIVE VALUES FROM ARDUINO1char string[4];int var;int index;boolean started=false;boolean ended=false;//SoftwareSerial steer(2); //steering connected to pin 0//SoftwareSerial brake(4); //brake connected to pin 1void setup(){ Serial.begin(9600); pinMode(2, OUTPUT); pinMode(4, OUTPUT);}void loop(){else if(ltr == 'B') //if pot1 changed, do this using value above { //This will be on channel 2. 128 = full reverse, 192=stop, 255=full forward if(val > 150) { //send 128 to the roboclaw Channel 2 to apply full brake digitalWrite(4, 128); //brake.write(128); } else { //send 255 to roboclaw to not brake digitalWrite(4, 255); //brake.write(255); } }}