Sunday, November 30, 2014

Code and Wiring


We made this setup for simple variable speed of a 12V DC motor using a potentiometer. The accompanying code is below. Now we have to figure out how to configure this type of setup to work with four motors hooked up to a motor shield in such a way that the motors on same sides run together and have each side run independently ( two joysticks).



int potPin = A0;
int motorPin = 9;
int potValue = 0;
int motorValue = 0;
void setup() {
 Serial.begin(9600);
}
void loop() {
 potValue = analogRead(potPin);  
 motorValue = map(potValue, 0, 1023, 0, 255);
 analogWrite(motorPin, motorValue);  
 Serial.print("potentiometer = " );     
 Serial.print(potValue);
 Serial.print("\t motor = ");
 Serial.println(motorValue);
 delay(2);    
}

No comments:

Post a Comment