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 725B

12345678910111213141516171819202122232425262728293031
  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. void Port_ShiftRegs::write(const uint8_t pin, const bool logicLevel)
  15. {
  16. if (logicLevel == LOW)
  17. {
  18. outputVal &= ~pin; //set pin output to low
  19. }
  20. else
  21. {
  22. outputVal |= pin; //set pin output to high
  23. }
  24. digitalWrite(slaveSelect, LOW);
  25. SPI.transfer(outputVal);
  26. digitalWrite (slaveSelect, HIGH);
  27. }