Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // read keypad from 1 analog pin ands do something when specific key is pressed
- // I tried to re-read inside case, but it's not working
- //add this for working
- // I add new readkeypad1() function with timeout for re-read from keypad
- // after reading the key I compare if not equal to KEY_NOT_PRESSED
- // and store the key
- #include <AnalogMatrixKeypad.h>
- #define analogPin 0
- AnalogMatrixKeypad AnMatrixKeypad(analogPin);
- #include <Wire.h>
- char Key,Key1,value;
- const int timeout = 1500;
- long timer;
- int x;
- void readkeypad()
- {
- Key = AnMatrixKeypad.readKey();
- if(Key != KEY_NOT_PRESSED)
- Serial.println(Key); // send pressed key to serial monitor
- }
- // ------ ------ ------ ------ code I add ------ ------ ------ ------
- void readkeypad1() //
- { //
- if(millis() - timer <= timeout) //
- { //
- Key1 = AnMatrixKeypad.readKey(); //
- if(Key1 != KEY_NOT_PRESSED){} //
- //Serial.println(Key1); //
- //if(Key1 == KEY_NOT_PRESSED) //
- //Serial.println(Key1); // send pressed key to serial monitor //
- else readkeypad1(); //
- } //
- } //
- // ------ ------ ------ ------ ------ ------ ------ ------ ------ ------
- void checkeypad()
- {
- switch (Key)
- {
- case 'A':
- Serial.println(Key);
- //Serial.println("Enter new value from keypad :");
- // readkeypad(); // read new value from keypad, not working
- //value=Key;
- //Serial.println("target :");
- //Serial.println(value); // print on the serial monitor this char '-'
- break;
- case 'B':
- Serial.println("Elapsed Time is: ");
- Serial.println(millis());
- break;
- // ------ ------ ------ ------ code I add ------ ------ ------ ------
- case '1': //
- if(millis() - timer1 <= timeout) //
- { //
- Serial.println("Enter new temp target :"); //
- timer2 = millis(); //
- readkeypad1(); //
- if(Key1 != KEY_NOT_PRESSED) //
- {x=Key1-'0';} // convert char to int, if you need //
- Serial.println("target :"); //
- Serial.println(desirabletemp); //
- } //
- break; //
- } //
- // ------ ------ ------ ------ ------ ------ ------ ------ ------ ------
- }
- void setup()
- {
- Wire.begin(); // join i2c bus (address optional for master)
- Serial.begin(9600);
- }
- void loop()
- {
- readkeypad(); // read from keypad
- checkeypad(); // check for key pressed
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement