Hardware Reference
In-Depth Information
velocity = map(val, 563, 1023, 0, 255);
forward(velocity);
}
//go backward
else if (val < 462)
{
velocity = map(val, 461, 0, 0, 255);
reverse(velocity);
}
//brake
else
{
brake();
}
}
//Motor goes forward at given rate (from 0-255)
void forward (int rate)
{
digitalWrite(EN, LOW);
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
analogWrite(EN, rate);
}
//Motor goes backward at given rate (from 0-255)
void reverse (int rate)
{
digitalWrite(EN, LOW);
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
analogWrite(EN, rate);
}
//Stops motor
void brake ()
{
digitalWrite(EN, LOW);
digitalWrite(MC1, LOW);
digitalWrite(MC2, LOW);
digitalWrite(EN, HIGH);
}
Does everything work as expected? If not, make sure that you wired up your
circuit correctly. As an additional challenge, grab a second DC motor and hook
it up to the other half of the H-bridge chip. You should be able to drive two
motors simultaneously with minimal effort.
Search WWH ::




Custom Search