hello everybody,
i am programming on arduino uno R3 with rich shield component.
for my study i need to make that when i push the button 9 te direction will switch eacht time from led1 ,2,3 and 3,2,1
my code i will put downstart can someone help me , and show what i did wront or forgot
const int buttonPin = 8; // the pin that the pushbutton is attached to
const int buttonPin1 = 9;
const int ledPin1 = 4; // the pin that the LED is attached to
const int ledPin2 = 5; // the pin that the LED is attached to
const int ledPin3 = 6; // the pin that the LED is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin1, INPUT_PULLUP);
// initialize the LED as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
bool forward = true ;
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
if (buttonState == LOW) {
if (forward == true )
buttonPushCounter++;
} else {
}
delay(200);
} if (digitalRead(9) == LOW)
// if (forward == true )
buttonPushCounter--;
// switch (buttonState);
{
lastButtonState = buttonState;
}
if (buttonPushCounter % 3 == 0) {
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, LOW);
} else {
}
if (buttonPushCounter % 3 == 1) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin3, LOW);
} else {
} if (buttonPushCounter % 3 == 2) {
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
digitalWrite(ledPin3, HIGH);
} else {
}
}