keybrd library is an open source library for creating custom-keyboard firmware.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
此仓库已存档。您可以查看文件和克隆,但不能推送或创建工单/合并请求。

PortRead_MCP23S17.ino 1009B

1234567891011121314151617181920212223242526272829303132
  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 "PortWrite_MCP23S17.h"
  12. const uint8_t PortIOE::ADDR = 0x20; //MCP23S17 address, all 3 ADDR pins are grounded
  13. PortIOE portB(1, 0);
  14. PortRead_MCP23S17 portBRead(portB);
  15. PortWrite_MCP23S17 portBWrite(portB); //PortBWrite needed for begin()
  16. void setup()
  17. {
  18. uint8_t portBState; //bit wise
  19. delay(6000);
  20. portBWrite.begin();
  21. portBState = portBRead.read();
  22. Keyboard.print("portBState = ");
  23. Keyboard.println(portBState, BIN); //should print 10101010
  24. }
  25. void loop() { }