Advertisement
noam76

read from keypad to array

May 11th, 2015
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. // read from keypad to array
  2. // in this code working
  3. // but when I use for loop it's not working properly the Key can enter to the same array several pressing.
  4.  
  5. #include <AnalogMatrixKeypad.h>
  6. #define analogPin 0
  7. AnalogMatrixKeypad AnMatrixKeypad(analogPin);
  8.  
  9. char Key,attempt[2];
  10. int i=0;
  11.  
  12. void setup()
  13. {
  14. Serial.begin(9600);
  15. }
  16.  
  17. void loop()
  18. {
  19. Key = AnMatrixKeypad.readKey();
  20. if (Key != KEY_NOT_PRESSED)
  21. {
  22. attempt[i]=Key;
  23. Serial.println(attempt[i]);
  24. i++;
  25. }
  26. if(i==2)
  27. i=0;
  28. }
  29.  
  30. -----------------------------------------------------------
  31.  
  32.  
  33. //for loop not working properly
  34. for(i=0; i<2; i++)
  35. {
  36. Key = AnMatrixKeypad.readKey();
  37. if (Key != KEY_NOT_PRESSED)
  38. {
  39. attempt[i]=Key;
  40. Serial.print("The Key ");
  41. Serial.println(attempt[i]);
  42. Serial.print("enter to the array ");
  43. Serial.println(i);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement