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.

PortRead_MCP23S17.ino 1007B

12345678910111213141516171819202122232425262728293031323334
  1. /* unit test for PortRead_MCP23S17
  2. The setup is an MCP23S17 I/O expander on a Teensy LC controller.
  3. MCP23S17 port-B pins are alternately grounded and energized.
  4. portBState is a bitwise reading of port B.
  5. output is: 10101010
  6. posted on http://arduino.stackexchange.com/questions/tagged/spi
  7. http://arduino.stackexchange.com/questions/28792/reading-an-mcp23s17-i-o-expander-port-with-the-arduino-spi-library
  8. */
  9. #include "PortIOE.h"
  10. #include "PortRead_MCP23S17.h"
  11. #include "Scanner_Port.h"
  12. const bool Scanner_Port::STROBE_ON = LOW;
  13. const bool Scanner_Port::STROBE_OFF = HIGH;
  14. const uint8_t PortIOE::DEVICE_ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
  15. PortIOE portB(1, 0);
  16. PortRead_MCP23S17 portBRead(portB, ~0);
  17. void setup()
  18. {
  19. uint8_t portBState; //bit wise
  20. delay(6000);
  21. portBRead.begin();
  22. portBState = portBRead.read();
  23. Keyboard.print("portBState = ");
  24. Keyboard.println(portBState, BIN); //prints 10101010
  25. }
  26. void loop() { }