lcd.setCursor(0,0); lcd.print(analogRead(0)); lcd.print(" "); lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over lcd.print(millis()/1000); // display seconds elapsed since power-up
// select the pins used on the LCD panel LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons int lcd_key = 0; int adc_key_in = 0; #define btnRIGHT 0 #define btnUP 1 #define btnDOWN 2 #define btnLEFT 3 #define btnSELECT 4 #define btnNONE 5
// read the buttons int read_LCD_buttons() { adc_key_in = analogRead(0); Serial.println(adc_key_in); delay(10); // read the value from the sensor // my buttons when read are centered at these valies: 0, 144, 329, 504, 741 // we add approx 50 to those values and check to see if we are close if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result // For V1.1 us this threshold if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 250) return btnUP; if (adc_key_in < 450) return btnDOWN; if (adc_key_in < 650) return btnLEFT; if (adc_key_in < 850) return btnSELECT;
// For V1.0 comment the other threshold and use the one below: /* if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 195) return btnUP; if (adc_key_in < 380) return btnDOWN; if (adc_key_in < 555) return btnLEFT; if (adc_key_in < 790) return btnSELECT; */
return btnNONE; // when all others fail, return this... }
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2); // start the library lcd.setCursor(0,0); lcd.print("Push the buttons"); // print a simple message }
void loop() { lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over lcd.print(millis()/1000); // display seconds elapsed since power-up
lcd.setCursor(0,1); // move to the begining of the second line lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action { case btnRIGHT: { lcd.print("RIGHT "); break; } case btnLEFT: { lcd.print("LEFT "); break; } case btnUP: { lcd.print("UP "); break; } case btnDOWN: { lcd.print("DOWN "); break; } case btnSELECT: { lcd.print("SELECT"); break; } case btnNONE: { lcd.print("NONE "); break; } }
}
Törölt felhasználó
2017-10-17 19:36:54
[743]
ez sorosportra kiirja azt a nyomogomb értékétet amit lenyomsz!
//Sample using LiquidCrystal library #include <LiquidCrystal.h>
// select the pins used on the LCD panel LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons int lcd_key = 0; int adc_key_in = 0; #define btnRIGHT 0 #define btnUP 1 #define btnDOWN 2 #define btnLEFT 3 #define btnSELECT 4 #define btnNONE 5
// read the buttons int read_LCD_buttons() { adc_key_in = analogRead(0); Serial.println(adc_key_in); delay(10); // read the value from the sensor // my buttons when read are centered at these valies: 0, 144, 329, 504, 741 // we add approx 50 to those values and check to see if we are close if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result // For V1.1 us this threshold if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 250) return btnUP; if (adc_key_in < 450) return btnDOWN; if (adc_key_in < 650) return btnLEFT; if (adc_key_in < 850) return btnSELECT;
// For V1.0 comment the other threshold and use the one below: /* if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 195) return btnUP; if (adc_key_in < 380) return btnDOWN; if (adc_key_in < 555) return btnLEFT; if (adc_key_in < 790) return btnSELECT; */
return btnNONE; // when all others fail, return this... }
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2); // start the library lcd.setCursor(0,0); lcd.print("Push the buttons"); // print a simple message }
void loop() { lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over lcd.print(millis()/1000); // display seconds elapsed since power-up
lcd.setCursor(0,1); // move to the begining of the second line lcd_key = read_LCD_buttons(); // read the buttons
switch (lcd_key) // depending on which button was pushed, we perform an action { case btnRIGHT: { lcd.print("RIGHT "); break; } case btnLEFT: { lcd.print("LEFT "); break; } case btnUP: { lcd.print("UP "); break; } case btnDOWN: { lcd.print("DOWN "); break; } case btnSELECT: { lcd.print("SELECT"); break; } case btnNONE: { lcd.print("NONE "); break; } }
Nem vagyok duinos ezért pszeudó kód: Define b as byte define sum as integer
.....
sum:=0; For b:=1 to 4 sum=sum+getadc(0); delay(5) next sum:=sum/4 print sum
....
Ez egy kicsit megszűri az ad értékeit, és kiírja. Ezután végignyomkodva a gombokat látod hol mi jön vissza. Így annak alapján tudod a gomb kiválasztás határértékeit a gombok értékei közé középre állítani.
Analog benenet érték 0...1023 értéken mozog 0...5v az elenálás létra fesz osztóként müxik
pl ha rosz az elenálás érték a pcb verzion akor rosz a definiált érték határ a kodban is ezért reagálhat is rosszul! pl if (adc_key_in < 195) return btnUP; lehet ez lesz helyes if (adc_key_in < 250) return btnUP;
Így már más a leányzó fekvése én tényleg a mátrixra gondoltam de mint az előttem szóló írta használj prellmentesítést , én a picben úgy csinálnám hogy nem értéket hanem tartományt adnék meg majd a beolvasás után figyelném hogy az adc mikor ment 0 ra és onnan indítanám a következő mérést
Csináld azt hogy néhányszor végzel egymás után ad konverziót pár mS késleltetéssel majd az átlagot használod fel, vagy addig olvasod az AD-t amíg három egymás utáni konverzió nem tér el egy limit értéknél jobban.
int lcd_key = 0; int adc_key_in = 0; int addr = 0;
byte E; byte H;
int read_LCD_buttons() { adc_key_in = analogRead(0); if (adc_key_in < 50) return btnRIGHT; if (adc_key_in < 195) return btnUP; if (adc_key_in < 380) return btnDOWN; if (adc_key_in < 555) return btnLEFT; if (adc_key_in < 790) return btnSELECT; return btnNONE; // when all others fail, return this...
A gomb beolvasás például:
case btnLEFT: //4. case { { H = H + 1; if ( H > E ) (E = E + 1 ); // H értéke nem haladhatja meg E-ét lcd.setCursor(8, 0); lcd.print(" "); lcd.setCursor(8, 0); lcd.print(E); lcd.setCursor(8, 1); lcd.print(" "); lcd.setCursor(8, 1); lcd.print(H); EEPROM.write(1, H); delay(200); break; }
Sajnos kénytelen vagyok ezt használni, a keypad shield tartalmazza az ellenállásokat és a gombokat. Nem maradt elég bemenet mind az 5 gombnak egyesével.
Hanyagold az ellenállás mérést , az arduinoban is van keypad mintapélda azt használd (én pices vagyok de a rendszer ugyan az ) a keypadnál azt figyeli mikor melyik két láb van összekötve a nyomobomb mátrixban
Kedves Arduino szakik! Adott egy UNO, keypad shield-el összecsatlakoztatva. A keypad gombjai az UNO analóg bemenetére kapcsolódnak, ellenállásméréssel határozza meg hogy melyik gombot nyomtam meg. A gond a következő: BtnUp gombra felfelé kéne számolnia, de a gomb elengedésekor néha lefelé is megteszi (erre is van gomb definiálva). Gondolom én hogy a nyomógomb prellezése okoz gondot. Hogyan lehetne kiküszöbölni?
Még mindig áll az ajánlatom a készre varázsolt bluethoot-ra!
Ha kell akkor akár arduinoval együtt is vevő vagyok rá! Vagy amennyiben inkognitóban akarsz maradni, nekem az is jó ha a VAKERA-s dolgaid közé felrakod!
Azt én már nem tudhatom. Kipróbálni nem tudom, mert (még!) nincs Arduinom. De nem lesz ez így már sokáig, mert minden érdekel, amit programozni lehet. (Na, jó, a mosógép nem...)
Ebben a cikkben az első válasz jó linket ad, az ott levő csomagban értelmezett ennyi paraméter az osztály konstruktorában és tudja, mi az a POSITIVE. (A NewliquidCrystal_1.3.4.zip-et töltöttem le, abba néztem bele.)
Az a könyvtár nem használja ezt az utasítást ebben a formában. Nyisd meg a könyvtárat és olvasd el milyen utasításokat használhatsz.Valamikor csak kis betü nagy betü probléma van.