Hi Folks, IM trying to set up a program so that when one button is pressed the motor turns one way, and when another button is pressed it will turn another. My problem is that the motor does not stay on when pressed once, the button has to stay on all the time for it to do this. Can anyone give me any advice?
My code is:
/*
sweeping motor control.
*/
int forwardswitchPin = 13;
int backswitchPin = 12;
int motor1APin = 6; // H-bridge leg 1
int motor2APin = 7; // H-bridge leg 2
void setup()
{
pinMode(forwardswitchPin, INPUT);
pinMode(backswitchPin, INPUT);
pinMode(motor1APin, OUTPUT);
pinMode(motor2APin, OUTPUT);
}
void loop()
{
if (digitalRead(forwardswitchPin) == HIGH)
{
digitalWrite(motor1APin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2APin, HIGH); // set leg 2 of the H-bridge high
}
else if (digitalRead(backswitchPin) == HIGH)
{
digitalWrite(motor1APin, HIGH); // set leg 1 of the H-bridge low
digitalWrite(motor2APin, LOW); // set leg 2 of the H-bridge low
}
}
here is how I have it wired up.
I am a technology teacher and trying to create a project where pupils will design and build a CCTV system where once movement is sensed it will start recording and sweeping around until it hits a switch, but I cant seem to get the actual motor control section figured out. Im very new to arduino and this has got me stumped. Can anyone help?
Thanks in advance.