Go Down

### Topic: I wrote a differential steering program...maybe it could be useful to you (Read 90 times)previous topic - next topic

#### max1213

I wrote this differential steering program for myself, but I thought it might be useful to someone else. I'm still kind of a beginner, so there is probably a more efficient way, but here it is:
Code: [Select]
`const int potmin = 26; //your pot turned all the way downconst int potmax = 1023; //your pot turned all the way upint potin; // this is where the input from pot 1 will be storedint potmapped;// the pot brought down to a value that will work with our outputsconst int potmin2 = 26;//the same things for pot 2const int potmax2 = 1023;int potin2;int potmapped2;int left;int right;const int pot = A0;// the pin numbers for the inputs and outputsconst int pot2 = A1;const int leftoutput = 11;const int rightoutput = 10;const int maxspeed = 255; //If you want to restrict the speed for some reason, put your max speed here.void setup() {  // put your setup code here, to run once:  pinMode(pot, INPUT);// set up the inputs and outputs  pinMode(pot2, INPUT);  pinMode(leftoutput, OUTPUT);  pinMode(rightoutput, OUTPUT);}void loop() {  // put your main code here, to run repeatedly:potin2 = analogRead(A1);//Get data frompotin = analogRead(A0);//the potspotmapped2 = map(potin2, potmin2, potmax2, 0, 255);// constrain it to a usable number in this programpotmapped = map(potin, potmin, potmax, 0, 510);left = constrain(map(potmapped , 0, 510, 0,potmapped2), 0, maxspeed);//map the left and right outputs depending on the steering and max speedright = constrain(map(510 - potmapped, 0, 510, 0,potmapped2), 0, maxspeed);analogWrite(leftoutput, left);analogWrite(rightoutput, right);delay(100);}`

Go Up