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.

PortWrite_PCA9655E.cpp 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "PortWrite_PCA9655E.h"
  2. /*
  3. If PortRead_PCA9655E is instantiated on the same port, do NOT use PortWrite_PCA9655E::begin().
  4. Otherwise readPins could be overwritten.
  5. */
  6. void PortWrite_PCA9655E::begin()
  7. {
  8. Wire.begin();
  9. Wire.beginTransmission(port.DEVICE_ADDR);
  10. Wire.write(port.num + 6); //configuration byte command
  11. Wire.write(0); //0=configure as output (for strobe pins and LED)
  12. Wire.endTransmission();
  13. }
  14. /*
  15. strobePin is bitwise, where pin being strobed is 1.
  16. pinLogicLevel is HIGH or LOW.
  17. Does not reset the other pins because LEDs could be using some of the pins.
  18. Syntax is similar to Arduino DigitalWrite().
  19. */
  20. void PortWrite_PCA9655E::write(const uint8_t strobePin, const bool pinLogicLevel)
  21. {
  22. if (pinLogicLevel == LOW) //if strobePin low
  23. {
  24. port.outputVal &= ~strobePin; //set pin output to low
  25. }
  26. else //if strobestrobe high
  27. {
  28. port.outputVal |= strobePin; //set pin output to high
  29. }
  30. Wire.beginTransmission(port.DEVICE_ADDR);
  31. Wire.write(port.num + 2); //output Byte command
  32. Wire.write(port.outputVal);
  33. Wire.endTransmission();
  34. }