Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. /* LAB3 BY HERNAN LOZANO */
  2. unsigned long ms_runtime;
  3. int one_ms_timer;
  4. //DEFINE ALL TIMERS AS UNSIGNED LONG
  5. // These timers are incremented every 100ms = 0.1s
  6. unsigned long timer1; // timer1 is used for blinking LED
  7. unsigned long button_dbnc_tmr = 0; // button_dbnc_tmr for debouncing input
  8. const int buttonPin = 2;
  9. const int LED1 = 13;
  10. unsigned int state; // possible values 0 -> 1 ... -> 9 -> 0
  11. void setup()
  12. {
  13. readmemory();
  14. }
  15. void loop()
  16. {
  17. static bool allow_change;
  18. static unsigned int old_state;
  19.  
  20. if(digitalRead(buttonPin) == 1)
  21. {
  22. if(allow_change == 1)
  23. {
  24. if(button_dbnc_tmr > 10)
  25. {
  26. allow_change = 0;
  27. state++;
  28. if(state > 9)
  29. state = 0;
  30. Serial.println(state);
  31. }
  32. }
  33. }
  34. else
  35. {
  36. allow_change = 1;
  37. button_dbnc_tmr = 0;
  38. }
  39. setLED(state);
  40. if (state != old_state)
  41. {
  42. updatememory(0,state);
  43. old_state = state;
  44. }
  45. }
  46. void setLED(int state)
  47. {
  48. switch(state)
  49. {
  50. case 0:
  51. analogWrite(LED1, 0);
  52. inctimers();
  53. break;
  54. case 1:
  55. analogWrite(LED1, 25);
  56. break;
  57. case 2:
  58. analogWrite(LED1, 50);
  59. break;
  60. case 3:
  61. analogWrite(LED1, 75);
  62. break;
  63. case 4:
  64. analogWrite(LED1, 100);
  65. break;
  66. case 5:
  67. analogWrite(LED1, 125);
  68. break;
  69. case 6:
  70. analogWrite(LED1, 150);
  71. break;
  72. case 7:
  73. analogWrite(LED1, 175);
  74. break;
  75. case 8:
  76. analogWrite(LED1, 200);
  77. break;
  78. case 9:
  79. analogWrite(LED1, 250); //maximum intensity
  80. break;
  81. default:
  82. break;
  83. }
  84. }
  85. int inctimers()
  86. {
  87. /*COMPLETE FUNCTION*/
  88. for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5)
  89. {
  90. // sets the value (range from 0 to 255):
  91. analogWrite(LED1, fadeValue);
  92. // wait for 30 milliseconds to see the dimming effect
  93. delay(200);
  94. }
  95. // fade out from max to min in increments of 5 points:
  96. for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5)
  97. {
  98. // sets the value (range from 0 to 255):
  99. analogWrite(LED1, fadeValue);
  100. // wait for 30 milliseconds to see the dimming effect
  101. delay(10);
  102. }
  103. }
  104. void readmemory()
  105. {
  106. /*COMPLETE FUNCTION*/
  107. //The arduino measures voltage from 0 - 500
  108.  
  109. }
  110. void updatememory(int address,int value)
  111. {
  112. /*COMPLETE FUNCTION*/
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement