Advertisement
Guest User

Raging fart sniffles

a guest
Nov 26th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <IRremote.h>
  3.  
  4. #define BRIGHTNESS 6
  5. #define RECV_PIN 10
  6. #define ALARM_BUZZER 8
  7.  
  8. IRrecv irrecv(RECV_PIN);
  9. decode_results results;
  10.  
  11. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  12.  
  13. volatile int seconds = 0;
  14. volatile int minutes = 0;
  15. volatile int hours = 0;
  16.  
  17. void setup(){
  18. lcd.begin(16, 2);
  19. Serial.begin(9600);
  20. irrecv.enableIRIn();
  21. digitalWrite(BRIGHTNESS, 100);
  22. pinMode(8, OUTPUT);
  23. pinMode(13, OUTPUT);
  24. pinMode(BRIGHTNESS, OUTPUT);
  25. cli();
  26. TCCR1A = 0;
  27. TCCR1B = 0;
  28. OCR1A = 15625;
  29. TCCR1B |= (1 << WGM12);
  30. TCCR1B |= (1 << CS10);
  31. TCCR1B |= (1 << CS12);
  32. TIMSK1 |= (1<< OCIE1A);
  33. sei();
  34. }
  35.  
  36. void loop(){
  37. if(irrecv.decode(&results)) {
  38. long controlValue = results.value;
  39. if(controlValue == 0xFF629D){
  40.  
  41. setTime();
  42. }
  43. }
  44. irrecv.resume();
  45.  
  46. brightness();
  47. alarmBuzzer();
  48.  
  49. }
  50.  
  51. ISR (TIMER1_COMPA_vect){
  52. time();
  53. }
  54.  
  55. ISR (TIMER1_OVF_vect){
  56. time();
  57. }
  58.  
  59. void time(){
  60. lcd.setCursor(0,0);
  61. if(hours < 10){
  62. lcd.print(0);
  63. }
  64. lcd.print(hours);
  65. lcd.print(":");
  66. if(minutes < 10){
  67. lcd.print(0);
  68. }
  69. lcd.print(minutes);
  70. lcd.print(":");
  71. if(seconds < 10){
  72. lcd.print(0);
  73. }
  74. lcd.print(seconds);
  75. seconds++;
  76. if(seconds == 60){
  77. minutes++;
  78. seconds = 0;
  79. if(minutes == 60){
  80. hours++;
  81. minutes = 0;
  82. }
  83. }
  84. if (hours >= 24){
  85. hours = 0;
  86. }
  87.  
  88. }
  89.  
  90.  
  91. void brightness(){
  92. if(hours >= 8 && hours < 21){
  93. analogWrite(6, 100);
  94. }else{
  95. analogWrite(6, 5);
  96. }
  97. }
  98.  
  99. void alarmBuzzer(){
  100. digitalWrite(8, HIGH);
  101. delay(500);
  102. digitalWrite(8, LOW);
  103. delay(500);
  104. }
  105.  
  106. void setTime(){
  107.  
  108. long control = 0;
  109.  
  110. while( control != 0xFF629D ){
  111. Serial.print("Change Time");
  112.  
  113. hours = remoteControl();
  114. Serial.print(hours);
  115. Serial.print(" num1 \n");
  116. hours = hours * 10;
  117. hours = hours + remoteControl();
  118.  
  119. Serial.print(hours);
  120. Serial.print(" num2 \n");
  121. minutes = remoteControl();
  122. Serial.print(minutes);
  123. Serial.print(" num3 \n");
  124. minutes = minutes * 10;
  125. Serial.print(minutes);
  126. Serial.print(" num4 \n");
  127. minutes = minutes + remoteControl();
  128. seconds = 0;
  129. time();
  130.  
  131. control = 0xFF629D;
  132. }
  133.  
  134. }
  135.  
  136. int remoteControl(){
  137.  
  138. irrecv.resume();
  139. while(!irrecv.decode(&results)){
  140. if(irrecv.decode(&results)) {
  141. long controlValue = results.value;
  142.  
  143.  
  144. switch(controlValue){
  145. //button setTime = mode
  146.  
  147. //button 0
  148. case 0xFF6897:
  149.  
  150. return 0;
  151.  
  152.  
  153. //button 1
  154. case 0xFF30CF:
  155. return 1;
  156.  
  157. //button 2
  158. case 0xFF18E7:
  159. return 2;
  160.  
  161. //button 3
  162. case 0xFF7A85:
  163.  
  164. return 3;
  165.  
  166. //button 4
  167. case 0xFF10EF:
  168. return 4;
  169.  
  170. //button 5
  171. case 0xFF38C7:
  172. return 5;
  173.  
  174. //button 6
  175. case 0xFF5AA5:
  176. return 6;
  177.  
  178. //button 7
  179. case 0xFF42BD:
  180. return 7;
  181.  
  182. //button 8
  183. case 0xFF4AB5:
  184. return 8;
  185.  
  186. //button 9
  187. case 0xFF52AD:
  188. return 9;
  189.  
  190. //Holding down any button
  191. case 0xFFFFFFFF:
  192. delay(500);
  193. break;
  194.  
  195. default:
  196. break;
  197. }
  198. irrecv.resume(); // Receive the next value
  199. }
  200. }
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement