Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include the library code:
- #include <LiquidCrystal.h>
- int byteincome = 0;
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- //Key message
- int adc_key_val[5] ={30, 150, 360, 535, 760 };
- String statuses[] = {"Coding", "Doing Homework", "Please Leave", "Away", "Sleeping", "Calling Home", "Gaming", "GET OUT"};
- String top[] = {'Status:', 'Adam:', 'Oliver:', 'Adam & Oliver:', 'Awesomeness'. 'OBEY:'};
- int NUM_KEYS = 5;
- int adc_key_in;
- int key=-1;
- int oldkey=-1;
- int mode = 0;
- int blp = 10;
- int i = 0;
- int j = 0;
- void setup() {
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- lcd.setCursor(0, 1);
- intro();
- Serial.begin(9600);
- pinMode(10, OUTPUT);
- digitalWrite(blp, HIGH);
- }
- void loop() {
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- adc_key_in = analogRead(0); // read the value from the sensor
- key = get_key(adc_key_in); // convert into key press
- if (key != oldkey) // if keypress is detected
- {
- delay(50); // wait for debounce time
- adc_key_in = analogRead(0); // read the value from the sensor
- key = get_key(adc_key_in); // convert into key press
- if (key != oldkey)
- {
- oldkey = key;
- if (key==0)
- {
- j++;
- if (j>5)
- {
- j = 0;
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(top[j]);
- lcd.setCursor(0, 1);
- lcd.write(statuses[i]);
- }
- if (key==3)
- {
- j--;
- if (j<0)
- {
- j = 5;
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(top[j]);
- lcd.setCursor(0, 1);
- lcd.write(statuses[i]);
- }
- if (key == 1) //down key
- {
- i--;
- if (i == -1)
- {
- i = 7;
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(top[j]);
- lcd.setCursor(0, 1);
- lcd.print(statuses[i]);
- }
- if (key == 2) //up key
- {
- i++;
- if (i>7)
- {
- i = 0;
- }
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(top[j]);
- lcd.setCursor(0, 1);
- lcd.print(statuses[i]);
- }
- else if (key == 4)
- {
- if (mode == 0)
- {
- mode = 1;
- lcd.noDisplay();
- digitalWrite(10, LOW);
- }
- else if (mode == 1)
- {
- mode = 2;
- lcd.display();
- digitalWrite(10, LOW);
- }
- else if (mode == 2)
- {
- mode = 0;
- lcd.display();
- digitalWrite(10, HIGH);
- }
- }
- }
- }
- }
- // Convert ADC value to key number
- int get_key(unsigned int input)
- { int k;
- for (k = 0; k < NUM_KEYS; k++)
- {
- if (input < adc_key_val[k])
- { return k; }
- }
- if (k >= NUM_KEYS)
- k = -1; // No valid key pressed
- return k;
- }
- int intro()
- {
- lcd.setCursor(0, 0);
- lcd.print("Select: Mode");
- lcd.setCursor(0, 1);
- lcd.print("Left/Right: Top");
- delay(1500);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Left/Right: Top");
- lcd.setCursor(0, 1);
- lcd.print("Up/Down: Scroll");
- delay(1500);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Up/Down: Scroll");
- lcd.setCursor(0, 1);
- lcd.print("Status:");
- delay(1500);
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Status:");
- lcd.setCursor(0, 1);
- lcd.print("Coding");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement