Components and supplies
Arduino Nano R3
Pushbutton Switch, Momentary
LilyPad LED Blue (5pcs)
Apps and platforms
Arduino IDE 2.0 (beta)
Project description
Code
Remembering the sequence of lit LEDs
arduino
1 #include <EEPROM.h> 2 3 boolean record=false; 4 boolean button_pressed=false; 5 int G=HIGH; 6 int R=HIGH; 7 int W=HIGH; 8 int End=HIGH; 9 int eeprom_address=0; 10 unsigned long Time=0; 11 12 void replay_the_sequence(){ 13 for (int index = 0 ; index < EEPROM.length(); index++) { 14 digitalWrite(EEPROM.read(index),HIGH); 15 delay(1000); 16 digitalWrite(EEPROM.read(index),LOW); 17 delay(1000); 18 } 19 20 } 21 22 void setup() { 23 Serial.begin(9600); 24 pinMode(A1,INPUT_PULLUP); 25 pinMode(A2,INPUT_PULLUP); 26 pinMode(A3,INPUT_PULLUP); 27 pinMode(A0,INPUT_PULLUP); 28 29 pinMode(5,OUTPUT); 30 pinMode(6,OUTPUT); 31 pinMode(7,OUTPUT); 32 33 } 34 35 void loop() { 36 G=digitalRead(A1); 37 R=digitalRead(A2); 38 W=digitalRead(A3); 39 End=digitalRead(A0); 40 digitalWrite(7,!G); 41 digitalWrite(6,!R); 42 digitalWrite(5,!W); 43 44 45 if ((G==0 or R==0 or W==0)and record==false) { 46 for (int i = 0 ; i < 30 ; i++) EEPROM.write(i, 0); 47 record=true; 48 eeprom_address=0; 49 } 50 51 if (record==true and button_pressed==false){ 52 53 if (G==0 or R==0 or W==0){ 54 button_pressed=true; 55 if (G==0) EEPROM.write(eeprom_address,7); 56 if (R==0) EEPROM.write(eeprom_address,6); 57 if (W==0) EEPROM.write(eeprom_address,5); 58 eeprom_address++; 59 Time=millis(); 60 } 61 } 62 if (G==1 and R==1 and W==1 and millis()-Time>300) button_pressed=false; 63 if (End==0 and record==true) record=false; 64 if (End==0 and record==false)replay_the_sequence(); 65 66 }
Remembering the sequence of lit LEDs
arduino
1 #include <EEPROM.h> 2 3 boolean record=false; 4 boolean button_pressed=false; 5 int G=HIGH; 6 int R=HIGH; 7 int W=HIGH; 8 int End=HIGH; 9 int eeprom_address=0; 10 unsigned long Time=0; 11 12 void replay_the_sequence(){ 13 for (int index = 0 ; index < EEPROM.length(); index++) { 14 digitalWrite(EEPROM.read(index),HIGH); 15 delay(1000); 16 digitalWrite(EEPROM.read(index),LOW); 17 delay(1000); 18 } 19 20 } 21 22 void setup() { 23 Serial.begin(9600); 24 pinMode(A1,INPUT_PULLUP); 25 pinMode(A2,INPUT_PULLUP); 26 pinMode(A3,INPUT_PULLUP); 27 pinMode(A0,INPUT_PULLUP); 28 29 pinMode(5,OUTPUT); 30 pinMode(6,OUTPUT); 31 pinMode(7,OUTPUT); 32 33 } 34 35 void loop() { 36 G=digitalRead(A1); 37 R=digitalRead(A2); 38 W=digitalRead(A3); 39 End=digitalRead(A0); 40 digitalWrite(7,!G); 41 digitalWrite(6,!R); 42 digitalWrite(5,!W); 43 44 45 if ((G==0 or R==0 or W==0)and record==false) { 46 for (int i = 0 ; i < 30 ; i++) EEPROM.write(i, 0); 47 record=true; 48 eeprom_address=0; 49 } 50 51 if (record==true and button_pressed==false){ 52 53 if (G==0 or R==0 or W==0){ 54 button_pressed=true; 55 if (G==0) EEPROM.write(eeprom_address,7); 56 if (R==0) EEPROM.write(eeprom_address,6); 57 if (W==0) EEPROM.write(eeprom_address,5); 58 eeprom_address++; 59 Time=millis(); 60 } 61 } 62 if (G==1 and R==1 and W==1 and millis()-Time>300) button_pressed=false; 63 if (End==0 and record==true) record=false; 64 if (End==0 and record==false)replay_the_sequence(); 65 66 }
Remembering the sequence of lit LEDS remebering each LED duration
arduino
1 #include <EEPROM.h> 2 3 struct LED_PLUS_TIME { 4 int PIN; 5 6 unsigned long Interval; 7 }; 8 9 boolean record=false; 10 boolean 11 button_pressed=false; 12 int G=HIGH; 13 int R=HIGH; 14 int W=HIGH; 15 int 16 End=HIGH; 17 int index=0; 18 int eeprom_address=0; 19 unsigned long Time=0; 20 21 LED_PLUS_TIME LED; 22 LED_PLUS_TIME L_AND_T; 23 24 25 void replay_the_sequence(){ 26 27 eeprom_address=0; 28 for (int i = 0 ; i < 10; i++) { 29 EEPROM.get(eeprom_address,L_AND_T); 30 31 digitalWrite(L_AND_T.PIN,HIGH); 32 delay(L_AND_T.Interval); 33 digitalWrite(L_AND_T.PIN,LOW); 34 35 delay(1000); 36 eeprom_address+=sizeof(L_AND_T); 37 } 38 39 } 40 41 42 void setup() { 43 Serial.begin(9600); 44 pinMode(A1,INPUT_PULLUP); 45 46 pinMode(A2,INPUT_PULLUP); 47 pinMode(A3,INPUT_PULLUP); 48 pinMode(A0,INPUT_PULLUP); 49 50 51 pinMode(5,OUTPUT); 52 pinMode(6,OUTPUT); 53 pinMode(7,OUTPUT); 54 55 56 } 57 58 void loop() { 59 G=digitalRead(A1); 60 R=digitalRead(A2); 61 62 W=digitalRead(A3); 63 End=digitalRead(A0); 64 digitalWrite(7,!G); 65 66 digitalWrite(6,!R); 67 digitalWrite(5,!W); 68 69 70 if ((G==0 71 or R==0 or W==0)and record==false) { 72 for (int i = 0 ; i < 100; i++) EEPROM.update(i, 73 0); 74 record=true; 75 eeprom_address=0; 76 index=0; 77 } 78 79 80 if (record==true and button_pressed==false){ 81 82 if (G==0 or R==0 83 or W==0){ 84 button_pressed=true; 85 if (G==0) LED.PIN=7; 86 87 if (R==0) LED.PIN=6; 88 if (W==0) LED.PIN=5; 89 Time=millis(); 90 91 } 92 } 93 if (G==1 and R==1 and W==1 and millis()-Time>300 and 94 button_pressed==true ) { 95 LED.Interval= millis()-Time; 96 EEPROM.put(eeprom_address,LED); 97 98 eeprom_address+=sizeof(LED); 99 button_pressed=false; 100 index++; 101 102 103 } 104 if (End==0 and record==true) record=false; 105 if (End==0 106 and record==false)replay_the_sequence(); 107 108 }
Remembering the sequence of lit LEDS remebering each LED duration
arduino
1 #include <EEPROM.h> 2 3 struct LED_PLUS_TIME { 4 int PIN; 5 unsigned long Interval; 6 }; 7 8 boolean record=false; 9 boolean button_pressed=false; 10 int G=HIGH; 11 int R=HIGH; 12 int W=HIGH; 13 int End=HIGH; 14 int index=0; 15 int eeprom_address=0; 16 unsigned long Time=0; 17 LED_PLUS_TIME LED; 18 LED_PLUS_TIME L_AND_T; 19 20 21 void replay_the_sequence(){ 22 eeprom_address=0; 23 for (int i = 0 ; i < 10; i++) { 24 EEPROM.get(eeprom_address,L_AND_T); 25 digitalWrite(L_AND_T.PIN,HIGH); 26 delay(L_AND_T.Interval); 27 digitalWrite(L_AND_T.PIN,LOW); 28 delay(1000); 29 eeprom_address+=sizeof(L_AND_T); 30 } 31 32 } 33 34 void setup() { 35 Serial.begin(9600); 36 pinMode(A1,INPUT_PULLUP); 37 pinMode(A2,INPUT_PULLUP); 38 pinMode(A3,INPUT_PULLUP); 39 pinMode(A0,INPUT_PULLUP); 40 41 pinMode(5,OUTPUT); 42 pinMode(6,OUTPUT); 43 pinMode(7,OUTPUT); 44 45 } 46 47 void loop() { 48 G=digitalRead(A1); 49 R=digitalRead(A2); 50 W=digitalRead(A3); 51 End=digitalRead(A0); 52 digitalWrite(7,!G); 53 digitalWrite(6,!R); 54 digitalWrite(5,!W); 55 56 57 if ((G==0 or R==0 or W==0)and record==false) { 58 for (int i = 0 ; i < 100; i++) EEPROM.update(i, 0); 59 record=true; 60 eeprom_address=0; 61 index=0; 62 } 63 64 if (record==true and button_pressed==false){ 65 66 if (G==0 or R==0 or W==0){ 67 button_pressed=true; 68 if (G==0) LED.PIN=7; 69 if (R==0) LED.PIN=6; 70 if (W==0) LED.PIN=5; 71 Time=millis(); 72 } 73 } 74 if (G==1 and R==1 and W==1 and millis()-Time>300 and button_pressed==true ) { 75 LED.Interval= millis()-Time; 76 EEPROM.put(eeprom_address,LED); 77 eeprom_address+=sizeof(LED); 78 button_pressed=false; 79 index++; 80 81 } 82 if (End==0 and record==true) record=false; 83 if (End==0 and record==false)replay_the_sequence(); 84 85 }
Remembering the last lit LED out of 3
arduino
1 #include <EEPROM.h> 2 byte led_to_lit=0; 3 byte led_lit=0; 4 5 void setup() { 6 Serial.begin(9600); 7 pinMode(A1,INPUT_PULLUP); 8 pinMode(A2,INPUT_PULLUP); 9 pinMode(A3,INPUT_PULLUP); 10 11 pinMode(5,OUTPUT); 12 pinMode(6,OUTPUT); 13 pinMode(7,OUTPUT); 14 led_to_lit=EEPROM.read(0); 15 digitalWrite(led_to_lit,HIGH); 16 } 17 18 void loop() { 19 if(digitalRead(A1)==0) led_to_lit=7; 20 if(digitalRead(A2)==0)led_to_lit=6; 21 if(digitalRead(A3)==0)led_to_lit=5; 22 23 if(led_to_lit!=0 and led_to_lit!=led_lit){ 24 if (led_to_lit==7){digitalWrite(7,HIGH);digitalWrite(6,LOW);digitalWrite(5,LOW);EEPROM.write(0, 7);} 25 if (led_to_lit==6){digitalWrite(7,LOW);digitalWrite(6,HIGH);digitalWrite(5,LOW);EEPROM.write(0, 6); } 26 if (led_to_lit==5){digitalWrite(7,LOW);digitalWrite(6,LOW);digitalWrite(5,HIGH);EEPROM.write(0, 5);} 27 EEPROM.write(0,led_to_lit ); 28 Serial.println(led_to_lit); 29 } 30 led_lit=led_to_lit; 31 32 }
Downloadable files
Connectivity
Connectivity
Comments
Only logged in users can leave comments