I have the project to build a robot for my school. It will record button pushes then move according to this record.
Before usig motors, i'm trying to do this using leds.
Thanks from posts from this community, I've succeed in recording button pushes in an array.
Now I'm trying to light the leds according to this array. I have 4 buttons with 4 leds and one button tu run the recording when it's ready.
I'm stuck in lighting the leds when I push the play_button.
I hope someone can help me...
Here's my script :
int arr[10];
boolean previous = LOW;
unsigned long time1 = 0;
int debounce = 200;
unsigned long time2 = 0;
int index_state = 0;
int play_button = 13; //define pin # for play button
int button[4] = {2,4,6,8}; //store button pins in an array
int leds[4] = {3,5,7,9}; //store led pins in an array
void setup()
{
for(int n=0;n<10;n++) arr[n] = 0;//initialisition
Serial.begin(9600);
}
void loop(){
boolean mode = digitalRead(2) || digitalRead(4) || digitalRead(6) || digitalRead (8);
while(mode == LOW) mode = digitalRead(2) || digitalRead(4) || digitalRead(6) || digitalRead (8);//wait here till one of the pushbutton goes high;
//Serial.println("value");
if( mode == HIGH && previous == LOW && millis() - time1 > debounce) {
//find out which one is high and store that value in array;
if(digitalRead(2)) arr[index_state] = 2;
else if(digitalRead(4)) arr[index_state] = 4;
else if(digitalRead(6)) arr[index_state] = 6;
else if(digitalRead(8)) arr[index_state] = 8;
else ;
//print the value and the index;
Serial.print(arr[index_state]);
Serial.print(" Stored in index: ");
Serial.println(index_state);
index_state = (index_state + 1) % 10;
//update value of time1 for button debouncing
time1 = millis();
}
//update the value of previous button state
previous = digitalRead(2) || digitalRead(4) || digitalRead(6) || digitalRead(8);
}
Thank you