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.

Port_ShiftRegs.cpp 974B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "Port_ShiftRegs.h"
  2. Port_ShiftRegs::Port_ShiftRegs(const uint8_t slaveSelect) : slaveSelect(slaveSelect)
  3. {
  4. pinMode(slaveSelect, OUTPUT);
  5. }
  6. /* begin() should be called once from sketch setup().
  7. Initializes shift register's shift/load pin.
  8. */
  9. void Port_ShiftRegs::begin()
  10. {
  11. digitalWrite(slaveSelect, HIGH);
  12. SPI.begin();
  13. }
  14. /* writeLow() sets pin output LOW.
  15. pin is bit pattern, where pin being set is 1.
  16. */
  17. void Port_ShiftRegs::writeLow(const uint8_t pin)
  18. {
  19. outputVal &= ~pin; //set pin output to low
  20. digitalWrite(slaveSelect, LOW);
  21. SPI.transfer(outputVal);
  22. digitalWrite (slaveSelect, HIGH);
  23. }
  24. /* writeHigh() sets pin output HIGH.
  25. pin is bit pattern, where pin being set is 1.
  26. */
  27. void Port_ShiftRegs::writeHigh(const uint8_t pin)
  28. {
  29. outputVal |= pin; //set pin output to high
  30. digitalWrite(slaveSelect, LOW);
  31. SPI.transfer(outputVal);
  32. digitalWrite (slaveSelect, HIGH);
  33. }