Question: Explain the code line by line and describe the main functions of the code 1 /*LAB3 BY HERNAN LOZANO * 2 #include 3 unsigned long

Explain the code line by line and describe the main functions of the code

Explain the code line by line and describe the main functions ofthe code 1 /*LAB3 BY HERNAN LOZANO * 2 #include 3 unsignedlong ms runtime; 4 int one ms timer; 5 //DEFINE ALL TIMERS

1 /*LAB3 BY HERNAN LOZANO * 2 #include 3 unsigned long ms runtime; 4 int one ms timer; 5 //DEFINE ALL TIMERS AS UNSIGNED LONG 6 // These timers are incremented every 100ms = 0.1s 7 unsigned long timer1 // timerl is used for blinking LED 8 unsigned long button dbnc tmr = 0; // button dbnc tmr for debouncing input 9 const int buttonpin-2; 10 const int LED1-13; 11 unsigned int state; // possible values 0->1 12 void setup () 13 14 15 16 void loop 17 18 -> 9 -> 0 readmemory ); static bool allow change; static unsigned int old state; 20 21 inctimers (); if (digitalRead (buttonpin) 23 2 4 25 26 -1) if (allowchange-1) - if (button dbnc tmr > 9) 28 29 30 31 32 button dbnc tmr0 statet+ if (state>9) state = 0; Serial.println (state) 3 4 35 3 6 37 38 39 40 else allow_change 1; button dbnc tmr 0; 42 43 setLED (state); if (state !old state) updatememory (0, state); old state state; 4 6 47 48 49 void setLED (int state) 50 51 52 53 5 4 switch (state) case 0: analogWrite (LED1, 0) break; 56 57 58 59 60 61 62 63 6 4 65 case 1: analogWrite (LED1, 128); break; case 2: analogWrite (LED1, 143); break; case 3: analogWrite (LED1, 159); break; case 4: analogWrite (LED1, 175); break; 67 68 69 70 71 72 73 7 4 75 76 case 5: analogWrite (LED1, 191); break; case 6: analogWrite (LED1, 207); break; case 7: analogWrite (LED1, 223); break; case 8: 78 79 80 81 analogWrite (LED1, 239); break; case 9: analogWrite (LED1, 255); case 8: 78 79 80 81 82 83 8 4 85 8 6 87 analogWrite (LED1, 239); break; case 9: analogWrite (LED1, 255); break; default: analogWrite (LED1, 0) break; 88 int inctimers () 89 90 91 92 93 94 95 96 97 98 if (millis )(ms runtime1)) ms runtime-ms runtime 1 one ms timer++; else if (ms runtime >millis ms runtime = millis(); if (one_ms_timer > 9) // every 100 ms f one ms timer - 0 button dbnc tmr++ timerl++ 100 101 102 void readmemory () 103 104 105 106 107 state EEPROM. read (state); EEPROM.write (0, state); Serial.begin (9600) 108 void updatememory (int address, int value) 109 110 EEPROM.update (0, state) 1 /*LAB3 BY HERNAN LOZANO * 2 #include 3 unsigned long ms runtime; 4 int one ms timer; 5 //DEFINE ALL TIMERS AS UNSIGNED LONG 6 // These timers are incremented every 100ms = 0.1s 7 unsigned long timer1 // timerl is used for blinking LED 8 unsigned long button dbnc tmr = 0; // button dbnc tmr for debouncing input 9 const int buttonpin-2; 10 const int LED1-13; 11 unsigned int state; // possible values 0->1 12 void setup () 13 14 15 16 void loop 17 18 -> 9 -> 0 readmemory ); static bool allow change; static unsigned int old state; 20 21 inctimers (); if (digitalRead (buttonpin) 23 2 4 25 26 -1) if (allowchange-1) - if (button dbnc tmr > 9) 28 29 30 31 32 button dbnc tmr0 statet+ if (state>9) state = 0; Serial.println (state) 3 4 35 3 6 37 38 39 40 else allow_change 1; button dbnc tmr 0; 42 43 setLED (state); if (state !old state) updatememory (0, state); old state state; 4 6 47 48 49 void setLED (int state) 50 51 52 53 5 4 switch (state) case 0: analogWrite (LED1, 0) break; 56 57 58 59 60 61 62 63 6 4 65 case 1: analogWrite (LED1, 128); break; case 2: analogWrite (LED1, 143); break; case 3: analogWrite (LED1, 159); break; case 4: analogWrite (LED1, 175); break; 67 68 69 70 71 72 73 7 4 75 76 case 5: analogWrite (LED1, 191); break; case 6: analogWrite (LED1, 207); break; case 7: analogWrite (LED1, 223); break; case 8: 78 79 80 81 analogWrite (LED1, 239); break; case 9: analogWrite (LED1, 255); case 8: 78 79 80 81 82 83 8 4 85 8 6 87 analogWrite (LED1, 239); break; case 9: analogWrite (LED1, 255); break; default: analogWrite (LED1, 0) break; 88 int inctimers () 89 90 91 92 93 94 95 96 97 98 if (millis )(ms runtime1)) ms runtime-ms runtime 1 one ms timer++; else if (ms runtime >millis ms runtime = millis(); if (one_ms_timer > 9) // every 100 ms f one ms timer - 0 button dbnc tmr++ timerl++ 100 101 102 void readmemory () 103 104 105 106 107 state EEPROM. read (state); EEPROM.write (0, state); Serial.begin (9600) 108 void updatememory (int address, int value) 109 110 EEPROM.update (0, state)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!