keybrd library is an open source library for creating custom-keyboard firmware.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

PCA9655E_4_scan_loop.ino 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* PCA9655E_4_scan_loop.ino
  2. does same as PCA9655E_2_scan.ino, but using keybrd library classes
  3. pictures in PCA9655E_2_scan/
  4. set port 1 pins
  5. read and print value of port 0
  6. measure port 1 pin voltages with a multimeter
  7. DESTINATION PIN PIN_NUMBER PIN DESTINATION
  8. x INT 1 24 VDD Teensy LC 3.3V
  9. SCL AD1 2 23 SDA Teensy LC 18
  10. GND AD2 3 22 SCL Teensy LC 19
  11. GND IO0_0 4 21 AD0 SCL
  12. GND IO0_1 5 20 IO1_6 x
  13. IO1_1 IO0_2 6 19 IO1_5 x
  14. GND IO0_3 7 18 IO1_4 x
  15. GND IO0_4 8 17 IO1_4 x
  16. GND IO0_5 9 16 IO1_3 x
  17. x IO0_6 10 15 IO1_2 x
  18. x IO0_7 11 14 IO1_1 IO0_2 strobe pin
  19. GND VSS 12 13 IO1_0 x
  20. */
  21. #include <Port_PCA9655E.h>
  22. #include <Scanner_IOE.h>
  23. const uint8_t ADDR = 0x18; //I2C address with AD2=GND AD1=SCL AD0=SCL
  24. Port_PCA9655E port0(ADDR, 0, ~0); //read all pins
  25. Port_PCA9655E port1(ADDR, 1, 0); //for strobe
  26. Scanner_IOE scanner_R(HIGH, port1, port0);
  27. void setup()
  28. {
  29. delay(6000);
  30. Keyboard.println("PCA9655E_scan_4_loop.ino");
  31. scanner_R.begin();
  32. }
  33. uint8_t port0_val; //bit pattern
  34. uint8_t errorCount = 0;
  35. int loopCount = 0;
  36. int wait = 0; //delayMicroseconds
  37. void status()
  38. {
  39. Keyboard.print(" loopCount=");
  40. Keyboard.print(loopCount);
  41. Keyboard.print(" wait=");
  42. Keyboard.println(wait);
  43. };
  44. void loop()
  45. {
  46. port0_val = scanner_R.scan(1<<1); //strobe pin 1
  47. if ( (B00111111 & port0_val) != B00000100 ) //expect xx000100, where xx float
  48. {
  49. Keyboard.print("port0_val=");
  50. Keyboard.print(port0_val, BIN);
  51. errorCount++;
  52. status();
  53. }
  54. loopCount++;
  55. if (loopCount > 32000 || errorCount > 10)
  56. {
  57. Keyboard.print("stop errorCount=");
  58. Keyboard.print(errorCount);
  59. status();
  60. while(1);
  61. }
  62. if (loopCount % 1000 == 0)
  63. {
  64. Keyboard.print(" progress");
  65. status();
  66. }
  67. if (loopCount > 22000)
  68. {
  69. wait++; //test other delays
  70. }
  71. delayMicroseconds(wait);
  72. }