Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- #define btnRIGHT 0 // Definizione dei numeri associati ai pulsanti
- #define btnUP 1
- #define btnDOWN 2
- #define btnLEFT 3
- #define btnSELECT 4
- #define btnNONE 5
- #define Backlight 10
- int stato = 0;
- int adc_key_in = 0;
- int Ultimo_lcd_key = 0;
- int lcd_key = 0;
- int read_LCD_buttons()
- {
- adc_key_in = analogRead(0); // Legge il valore del convertitore ADC
- // I miei pulsanti danno questi valori: 0, 132, 321, 490, 725 (R,U,D,L,S)
- if (adc_key_in > 800) return btnNONE; // "None" per primo per velocizzare
- if (adc_key_in < 50) return btnRIGHT;
- if (adc_key_in < 200) return btnUP;
- if (adc_key_in < 400) return btnDOWN;
- if (adc_key_in < 500) return btnLEFT;
- if (adc_key_in < 800) return btnSELECT;
- return btnNONE; // Se nessun pulsante viene premuto...
- }
- void setup() {
- Serial.begin(9600);
- pinMode(Backlight, OUTPUT);
- digitalWrite(Backlight, HIGH); // Accende retroilluminazione
- lcd.begin(16, 2);
- }
- void loop() {
- lcd_key = read_LCD_buttons(); // Fa partire la funzione che legge i bottoni
- if ( lcd_key != Ultimo_lcd_key ) {
- Serial.println(stato);
- if ( lcd_key == btnUP) { //tasto up
- stato ++ ;
- }
- if (lcd_key == btnDOWN) {
- stato --;
- }
- Ultimo_lcd_key = lcd_key;
- }
- lcd.setCursor(0, 0);
- lcd.print("stato "); lcd.print(stato );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement