keybrd library is an open source library for creating custom-keyboard firmware.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.

Scanner_ShiftRegsRead.cpp 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "Scanner_ShiftRegsRead.h"
  2. /* constructor
  3. Parameter activeState is not used.
  4. */
  5. Scanner_ShiftRegsRead::Scanner_ShiftRegsRead(const bool activeState,
  6. const uint8_t slaveSelect, const uint8_t byte_count)
  7. : slaveSelect(slaveSelect), byte_count(byte_count)
  8. {
  9. pinMode(slaveSelect, OUTPUT);
  10. }
  11. /* init() is called once for each row from Row constructor.
  12. */
  13. void Scanner_ShiftRegsRead::init(const uint8_t strobePin)
  14. {
  15. //empty function
  16. }
  17. /* begin() should be called once from sketch setup().
  18. Initializes shift register's shift/load pin.
  19. */
  20. void Scanner_ShiftRegsRead::begin()
  21. {
  22. SPI.begin();
  23. digitalWrite(slaveSelect, HIGH);
  24. }
  25. /* scan() returns state of the shift register's input pins.
  26. Parameter strobePin is not used.
  27. No strobe pin is needed, the shift register is wired so the strobe is effectivley always "on".
  28. Bit patterns are 1 bit per key.
  29. */
  30. read_pins_t Scanner_ShiftRegsRead::scan(const uint8_t strobePin)
  31. {
  32. read_pins_t readState = 0; //bits, 1 means key is pressed, 0 means released
  33. //read all the column pins
  34. digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output
  35. SPI.transfer(&readState, byte_count);
  36. digitalWrite(slaveSelect, LOW); //load parallel inputs to the register
  37. return readState;
  38. }