Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* LAB3 BY HERNAN LOZANO */
- unsigned long ms_runtime;
- int one_ms_timer;
- //DEFINE ALL TIMERS AS UNSIGNED LONG
- // These timers are incremented every 100ms = 0.1s
- unsigned long timer1; // timer1 is used for blinking LED
- unsigned long button_dbnc_tmr = 0; // button_dbnc_tmr for debouncing input
- const int buttonPin = 2;
- const int LED1 = 13;
- unsigned int state; // possible values 0 -> 1 ... -> 9 -> 0
- void setup()
- {
- readmemory();
- }
- void loop()
- {
- static bool allow_change;
- static unsigned int old_state;
- if(digitalRead(buttonPin) == 1)
- {
- if(allow_change == 1)
- {
- if(button_dbnc_tmr > 10)
- {
- allow_change = 0;
- state++;
- if(state > 9)
- state = 0;
- Serial.println(state);
- }
- }
- }
- else
- {
- allow_change = 1;
- button_dbnc_tmr = 0;
- }
- setLED(state);
- if (state != old_state)
- {
- updatememory(0,state);
- old_state = state;
- }
- }
- void setLED(int state)
- {
- switch(state)
- {
- case 0:
- analogWrite(LED1, 0);
- inctimers();
- break;
- case 1:
- analogWrite(LED1, 25);
- break;
- case 2:
- analogWrite(LED1, 50);
- break;
- case 3:
- analogWrite(LED1, 75);
- break;
- case 4:
- analogWrite(LED1, 100);
- break;
- case 5:
- analogWrite(LED1, 125);
- break;
- case 6:
- analogWrite(LED1, 150);
- break;
- case 7:
- analogWrite(LED1, 175);
- break;
- case 8:
- analogWrite(LED1, 200);
- break;
- case 9:
- analogWrite(LED1, 250); //maximum intensity
- break;
- default:
- break;
- }
- }
- int inctimers()
- {
- /*COMPLETE FUNCTION*/
- for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)
- {
- // sets the value (range from 0 to 255):
- analogWrite(LED1, fadeValue);
- // wait for 30 milliseconds to see the dimming effect
- delay(200);
- }
- // fade out from max to min in increments of 5 points:
- for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)
- {
- // sets the value (range from 0 to 255):
- analogWrite(LED1, fadeValue);
- // wait for 30 milliseconds to see the dimming effect
- delay(10);
- }
- }
- void readmemory()
- {
- /*COMPLETE FUNCTION*/
- //The arduino measures voltage from 0 - 500
- }
- void updatememory(int address,int value)
- {
- /*COMPLETE FUNCTION*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement