Hi all,
Im working on a project and have hit a wall and unfortunately dont have the experience with writing code to figure the next part out and at this point of frustration and confusion im ready to admit temporary defeat and ask for help. I need to add a mode select single push button to change through 3 maybe 4 programmes, adding LEDs to indicate the change in programme would be cool but not essential, im using arduino uno and a l298n motor shield to a servo all running of 7.4v lipo battery, any help would be gratefully appreciated.
The code so far
int pinpwm = 13;//motor pwm channel
int pindirC = 7;//motor direction clockwise
int pindirAC = 8;
int spead =10000;//motor speed
void setup()
{
pinMode(pinpwm,OUTPUT);
pinMode(pindirC,OUTPUT);
pinMode(pindirAC,OUTPUT);
}
void forward()
{
digitalWrite(pindirC, HIGH);
digitalWrite(pindirAC, LOW);
analogWrite(pinpwm,spead);
}
void backward()
{
digitalWrite(pindirC, LOW);
digitalWrite(pindirAC, HIGH);
analogWrite(pinpwm,spead);
}
void stop()//
{
digitalWrite(pindirC, LOW);
digitalWrite(pindirAC, LOW);
delay(1000);
}
void loop()
{
delay(0);
forward();
delay(200);
stop();
forward();
delay(170);
stop();
forward();
delay(130);
stop();
forward();
delay(100);
stop();
forward();
delay(80);
stop();
delay(3000);
backward();
delay(500);
stop();
delay(3000);
//loop delay(0);
}