Advertisement
Guest User

Untitled

a guest
Aug 1st, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.04 KB | None | 0 0
  1. // include the library code:
  2. #include <LiquidCrystal.h>
  3. int byteincome = 0;
  4. // initialize the library with the numbers of the interface pins
  5. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  6.  
  7. //Key message
  8. int adc_key_val[5] ={30, 150, 360, 535, 760 };
  9. String statuses[] = {"Coding", "Doing Homework", "Please Leave", "Away", "Sleeping", "Calling Home", "Gaming", "GET OUT"};
  10. String top[] = {'Status:', 'Adam:', 'Oliver:', 'Adam & Oliver:', 'Awesomeness'. 'OBEY:'};
  11. int NUM_KEYS = 5;
  12. int adc_key_in;
  13. int key=-1;
  14. int oldkey=-1;
  15. int mode = 0;
  16. int blp = 10;
  17. int i = 0;
  18. int j = 0;
  19. void setup() {
  20. // set up the LCD's number of columns and rows:
  21. lcd.begin(16, 2);
  22. lcd.setCursor(0, 1);
  23. intro();
  24. Serial.begin(9600);
  25. pinMode(10, OUTPUT);
  26. digitalWrite(blp, HIGH);
  27.  
  28.  
  29. }
  30.  
  31. void loop() {
  32. // set the cursor to column 0, line 1
  33. // (note: line 1 is the second row, since counting begins with 0):
  34.  
  35.  
  36. adc_key_in = analogRead(0); // read the value from the sensor
  37.  
  38. key = get_key(adc_key_in); // convert into key press
  39. if (key != oldkey) // if keypress is detected
  40. {
  41. delay(50); // wait for debounce time
  42. adc_key_in = analogRead(0); // read the value from the sensor
  43. key = get_key(adc_key_in); // convert into key press
  44. if (key != oldkey)
  45. {
  46. oldkey = key;
  47.  
  48. if (key==0)
  49. {
  50.   j++;
  51.   if (j>5)
  52.   {
  53.     j = 0;
  54.   }
  55.   lcd.clear();
  56.   lcd.setCursor(0, 0);
  57.   lcd.print(top[j]);
  58.   lcd.setCursor(0, 1);
  59.  
  60.   lcd.write(statuses[i]);
  61.  
  62. }
  63. if (key==3)
  64. {
  65.   j--;
  66.   if (j<0)
  67.   {
  68.     j = 5;
  69.   }
  70.   lcd.clear();
  71.   lcd.setCursor(0, 0);
  72.   lcd.print(top[j]);
  73.   lcd.setCursor(0, 1);
  74.  
  75.   lcd.write(statuses[i]);
  76.  
  77. }
  78. if (key == 1) //down key
  79. {
  80.   i--;
  81.   if (i == -1)
  82.   {
  83.     i = 7;
  84.   }
  85.   lcd.clear();
  86.   lcd.setCursor(0, 0);
  87.   lcd.print(top[j]);
  88.   lcd.setCursor(0, 1);
  89.   lcd.print(statuses[i]);
  90.  
  91. }
  92. if (key == 2) //up key
  93. {
  94.   i++;
  95.   if (i>7)
  96.   {
  97.     i = 0;
  98.   }
  99.   lcd.clear();
  100.   lcd.setCursor(0, 0);
  101.   lcd.print(top[j]);
  102.   lcd.setCursor(0, 1);
  103.   lcd.print(statuses[i]);
  104.  
  105. }
  106. else if (key == 4)
  107. {
  108.   if (mode == 0)
  109.   {
  110.     mode = 1;
  111.     lcd.noDisplay();
  112.     digitalWrite(10, LOW);
  113.   }
  114.   else if (mode == 1)
  115.  
  116.   {
  117.     mode = 2;
  118.     lcd.display();
  119.     digitalWrite(10, LOW);
  120.   }
  121.  
  122.     else if (mode == 2)
  123.   {
  124.     mode = 0;
  125.     lcd.display();
  126.     digitalWrite(10, HIGH);
  127.   }
  128. }
  129. }
  130. }
  131. }
  132.  
  133. // Convert ADC value to key number
  134. int get_key(unsigned int input)
  135. { int k;
  136. for (k = 0; k < NUM_KEYS; k++)
  137. {
  138. if (input < adc_key_val[k])
  139. { return k; }
  140. }
  141. if (k >= NUM_KEYS)
  142. k = -1; // No valid key pressed
  143. return k;
  144.  
  145.  
  146. }
  147. int intro()
  148. {
  149.  lcd.setCursor(0, 0);
  150.  lcd.print("Select: Mode");
  151.  lcd.setCursor(0, 1);
  152.   lcd.print("Left/Right: Top");
  153.   delay(1500);
  154.   lcd.clear();
  155.  lcd.setCursor(0, 0);
  156.   lcd.print("Left/Right: Top");
  157.  lcd.setCursor(0, 1);
  158.   lcd.print("Up/Down: Scroll");
  159.    delay(1500);
  160.   lcd.clear();
  161.  lcd.setCursor(0, 0);
  162.   lcd.print("Up/Down: Scroll");
  163.  lcd.setCursor(0, 1);
  164.   lcd.print("Status:");
  165.    delay(1500);
  166.   lcd.clear();
  167.  lcd.setCursor(0, 0);
  168.   lcd.print("Status:");
  169.  lcd.setCursor(0, 1);
  170.   lcd.print("Coding");
  171.   return 0;
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement