Non-Arduino keyMatrix library with Arduino support.

noarduino.c 1005B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Author: klaute -Kai Lauterbach - @kailauterbach - me@klaute.de
  3. * Date: 04/2016
  4. * License: GPLv3
  5. */
  6. /*
  7. #include <avr/io.h>
  8. #import "keymatrix.h"
  9. int main(void)
  10. {
  11. // call at start of the program
  12. km_init();
  13. // loop forever
  14. for (;;)
  15. {
  16. // call as often as you think that you need updated key states
  17. // for example every 50 ms are quite ok for me
  18. km_updateKeyStates();
  19. uint8_t key = km_getLastChangedKey();
  20. if (key >= KEYMATRIX_COLUMNS*KEYMATRIX_ROWS)
  21. {
  22. uint8_t state = km_getKeyState(key);
  23. switch(key)
  24. {
  25. case 0:;
  26. if (state == KEY_STATE_DOWN)
  27. {
  28. // do the key 0 action
  29. }
  30. break;
  31. case 1:;
  32. if (state == KEY_STATE_GO_DOWN)
  33. {
  34. // do the key 1 action
  35. }
  36. break;
  37. // ...
  38. case 23:;
  39. // do the key 23 action
  40. break;
  41. default:;
  42. // do other things
  43. }
  44. }
  45. }
  46. return 0;
  47. }
  48. */