Advertisement
safwan092

Simple Code to take input from user

May 13th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. #include <Keypad.h>
  2. long value = 0;
  3. const byte ROWS = 4; //four rows
  4. const byte COLS = 4; //four columns
  5. char keys[ROWS][COLS] = {
  6.   {'1', '4', '7', '*'},
  7.   {'2', '5', '8', '0'},
  8.   {'3', '6', '9', '#'},
  9.   {'A', 'B', 'C', 'D'}
  10. };
  11. byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad
  12. byte colPins[COLS] = {11, 10, 9, 8}; //connect to the column pinouts of the keypad
  13. Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
  14. void setup() {
  15.   Serial.begin(9600);
  16. }
  17. void loop() {
  18.  
  19.   char key = keypad.getKey();
  20.   if (key == 'A' || key == 'B' || key == 'C' || key == 'D') {
  21.     Serial.print("");
  22.   }
  23.   else Serial.print(key);
  24.   delay(1);
  25.   if (key != NO_KEY)
  26.   {
  27.     if ( (key >= '0') && (key <= '9') )
  28.     {
  29.       value = value * 10;
  30.       value = value + key - '0';
  31.     }
  32.     if ( key == 'A' )
  33.     {
  34.       Serial.println();
  35.       Serial.println(value);
  36.       // Remove this line and add it to the sensor value checker complete
  37.       value = 0; //Now reset ready for next input
  38.     }
  39.   }
  40.   if (key == 'B')
  41.   {
  42.     value = 0; //Now reset ready for next input
  43.     Serial.println();
  44.     Serial.println("Enter A New Number Please:");
  45.   }
  46.   if (key == 'C')
  47.   {
  48.     // Do whatever you like
  49.     //digitalWrite(ValvePin, LOW); // if relay is Active LOW
  50.   }
  51.   if (key == 'D')
  52.   {
  53.     // Do whatever you like
  54.     //digitalWrite(ValvePin, HIGH); // if relay is Active LOW
  55.   }
  56.  
  57. }//end of loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement