hey,
here is my modified code for selecting forth or back. it works fine. the next question is .. how iam able to let it count random?
thank you
// Number of Button location
int buttonPin = 22;
// Array of where leds are
int ledPinArray[] = {30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45};
// Current location in array
int pos = 0;
// read button state
int buttonState = 0;
int mode1 = 8;
int mode2 = 9;
int mode1status;
int mode2status;
void setup() {
// initialize the LEDs as an output
for(int i = 0; i < 16; i++)
//for(int i = 15; i > 16; i--)
{ // Change 4 to length of array
pinMode(ledPinArray[i],OUTPUT);
}
// Accept inputs from button pin
pinMode(buttonPin, INPUT);
// Turn on the first LED
digitalWrite(ledPinArray[0],HIGH);
//digitalWrite(30,HIGH);
}
void vor()
{
// read the state of the pushbutton
buttonState = digitalRead(buttonPin);
// if the button is preseed
if (buttonState == HIGH) {
// increment location in Array
pos++;
// if the location is higher than the length of the array, set it back to 0
if(pos >= 16) {
pos = 0;
}
// turn on next LED
digitalWrite(ledPinArray[pos], HIGH);
// Turns off last LED
if(pos!=0) { // If the current possition isnt the first in the row
digitalWrite(ledPinArray[pos-1], LOW);
} else { // If it is, turn off the last one
digitalWrite(ledPinArray[15],LOW);
}
// without this, it will change LED's faster than you can let go of the button
delay(10);
}
}
void back(){
// read the state of the pushbutton
buttonState = digitalRead(buttonPin);
// if the button is preseed
if (buttonState == HIGH) {
// increment location in Array
pos--;
// if the location is higher than the length of the array, set it back to 0
if(pos <= -1) {
pos = 15;
}
// turn on next LED
digitalWrite(ledPinArray[pos], HIGH);
// Turns off last LED
if(pos!=15) { // If the current possition isnt the first in the row
digitalWrite(ledPinArray[pos+1], LOW);
} else { // If it is, turn off the first one
digitalWrite(ledPinArray[0],LOW);
}
// without this, it will change LED's faster than you can let go of the button
delay(10);
}
}
void zufall();
void loop(){
mode1status = digitalRead(mode1);
mode2status = digitalRead(mode2);
{if(mode1status == LOW)
vor();
else
back();}
{if(mode2status == HIGH)
zufall();
else
vor();
}
}