Thank you both for your quick replies.
Calin Tamaian thank you for your shortcut but what MAS3 said is that I have to take it step by step.
MAS3 my brother is a programmer and helpt me a lot with the structure and it works now and understand nearly intirely:). My code at this moment is like this:
// constants won't change. They're used here to
// set pin numbers:
const int upButtonPin = 8; // the number of the pushbutton pin
const int downButtonPin = 9;
const int firstGearLed = 2; //
const int secondGearLed = 3; //
const int thirdGearLed = 4; //
const int fourthGearLed = 5; //
const int fifthGearLed = 6; //
const int sixthGearLed = 7; //
int gearNumber = 0;
int upButtonState = 0;
int downButtonState = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(firstGearLed, OUTPUT);
pinMode(secondGearLed, OUTPUT);
pinMode(thirdGearLed, OUTPUT);
pinMode(fourthGearLed, OUTPUT);
pinMode(fifthGearLed, OUTPUT);
pinMode(sixthGearLed, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(upButtonPin, INPUT);
pinMode(downButtonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
upButtonState = digitalRead(upButtonPin);
downButtonState = digitalRead(downButtonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (upButtonState == HIGH) {
if ( (gearNumber >= 0) && gearNumber <= 6){
gearNumber = gearNumber + 1;
delay(500);
// gearNumber = gearNumber + 1;
switch(gearNumber){
case 1:
digitalWrite(firstGearLed, HIGH);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, LOW);
break;
case 2:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, HIGH);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, LOW);
break;
case 3:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, HIGH);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, LOW);
break;
case 4:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, HIGH);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, LOW);
break;
case 5:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, HIGH);
digitalWrite(sixthGearLed, LOW);
break;
case 6:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, HIGH);
break;
}
}
}
//DOWN SHIFT
if (downButtonState == HIGH) {
if (gearNumber >= 1){
gearNumber = gearNumber - 1;
delay(500);
// gearNumber = gearNumber + 1;
switch(gearNumber){
case 6:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, HIGH);
break;
case 5:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, HIGH);
digitalWrite(sixthGearLed, LOW);
break;
case 4:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, HIGH);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, LOW);
break;
case 3:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, HIGH);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, LOW);
break;
case 2:
digitalWrite(firstGearLed, LOW);
digitalWrite(secondGearLed, HIGH);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, LOW);
break;
case 1:
digitalWrite(firstGearLed, HIGH);
digitalWrite(secondGearLed, LOW);
digitalWrite(thirdGearLed, LOW);
digitalWrite(fourthGearLed, LOW);
digitalWrite(fifthGearLed, LOW);
digitalWrite(sixthGearLed, LOW);
break;
}
}
}
}
My next goal is to use the button press to turn a servo to a programmed state in 6 steps. I ll try first and comeback with the code I produced:)
Thank you again!