Advertisement
CamolaZ

SC stop cycle

Aug 28th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1.  
  2. #include <Keypad.h>
  3.  
  4. const byte ROWS = 4; //four rows
  5. const byte COLS = 4; //four columns
  6. char keys[ROWS][COLS] = {
  7.   {'1','2','3','A'},
  8.   {'4','5','6','B'},
  9.   {'7','8','9','C'},
  10.   {'#','0','*','D'}
  11. };
  12. byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
  13. byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad
  14.  
  15. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  16. byte ledPin = 13;
  17.  
  18. boolean blink = false;
  19.  
  20. enum state {WAITING, LOOPING} current_state = WAITING;
  21.  
  22. void setup(){
  23.   Serial.begin(9600);
  24.   pinMode(ledPin, OUTPUT);      // sets the digital pin as output
  25.   digitalWrite(ledPin, HIGH);   // sets the LED on
  26.   keypad.addEventListener(keypadEvent); //add an event listener for this keypad
  27. }
  28.  
  29. void loop(){
  30.   char key = keypad.getKey();
  31.  
  32.   if (key != NO_KEY) {
  33.     Serial.println(key);
  34.   }
  35.  
  36.   switch(current_state) {
  37.   case WAITING:
  38.   // outside of loop, do nothing
  39.     break;
  40.   case LOOPING:
  41.   // set some parameters.  this set of code will be processed until no longer
  42.   // LOOPING, as set by the keyPadEvent.
  43.     break;
  44.   }    
  45. }
  46.  
  47. //take care of some special events
  48. void keypadEvent(KeypadEvent key){
  49.   switch (keypad.getState()){
  50.     case PRESSED:
  51.       switch (key){
  52.         case '#': current_state = LOOPING; break; // enter the function with "#"
  53.         case EXITKEY: current_state = WAITING; break; // exit the function with EXITKEY
  54.       }
  55.     break;
  56.  
  57.   }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement