Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h> // добавляем необходимые библиотеки
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7 );
- // Нажатые кнопки
- int button;
- const int BUTTON_NONE = 0;
- const int BUTTON_RIGHT = 1;
- const int BUTTON_UP = 2;
- const int BUTTON_DOWN = 3;
- const int BUTTON_LEFT = 4;
- const int BUTTON_SELECT = 5;
- int getPressedButton()
- {
- int buttonValue = analogRead(0); // считываем значения с аналогового входа(A0)
- if (buttonValue < 100) {
- return BUTTON_RIGHT;
- }
- else if (buttonValue < 200) {
- return BUTTON_UP;
- }
- else if (buttonValue < 400){
- return BUTTON_DOWN;
- }
- else if (buttonValue < 600){
- return BUTTON_LEFT;
- }
- else if (buttonValue < 800){
- return BUTTON_SELECT;
- }
- return BUTTON_NONE;
- }
- void setup()
- {
- lcd.begin(16, 2);
- }
- void loop()
- {
- button = getPressedButton();
- if(button){
- lcd.setCursor(0, 0);
- lcd.print(" ");
- lcd.setCursor(0, 0);
- lcd.print("BUTTON: ");
- }
- switch (button)
- {
- case BUTTON_RIGHT: // при нажатии кнопки выводим следующий текст
- lcd.print("RIGHT");
- break;
- case BUTTON_LEFT:
- lcd.print("LEFT");
- break;
- case BUTTON_UP:
- lcd.print("UP");
- break;
- case BUTTON_DOWN:
- lcd.print("DOWN");
- break;
- case BUTTON_SELECT:
- lcd.print("SELECT");
- break;
- }
- while(button>0){button = getPressedButton();}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement