Hardware Reference
In-Depth Information
• The setup() function, which sets the directionA , directionB , brakeA ,
and brakeB digital output pins:
pinMode(directionA, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(directionB, OUTPUT);
pinMode(brakeB, OUTPUT);
• The loop() function. This is an example of how to make the wheeled robot go
forward and then turn to the right. At each of these steps, you'll need to use the
brake to stop the robot. The code is as follows:
// Move forward
digitalWrite(directionA, HIGH);
digitalWrite(brakeA, LOW);
analogWrite(pwmA, 255);
digitalWrite(directionB, HIGH);
digitalWrite(brakeB, LOW);
analogWrite(pwmB, 255);
delay(2000);
digitalWrite(brakeA, HIGH);
digitalWrite(brakeB, HIGH);
delay(1000);
//Turn right
digitalWrite(directionA, LOW); //Establishes backward
direction of Channel A
digitalWrite(brakeA, LOW); //Disengage the Brake for
Channel A
analogWrite(pwmA, 128); //Spins the motor on Channel
A at half speed
digitalWrite(directionB, HIGH); //Establishes forward
direction of Channel B
digitalWrite(brakeB, LOW); //Disengage the Brake for
Channel B
analogWrite(pwmB, 128); //Spins the motor on Channel
Search WWH ::




Custom Search