2022-01-07 14:23:20 -05:00
|
|
|
//
|
|
|
|
// FILE: MCP23S17_digitalRead.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-08-14 06:56:15 -04:00
|
|
|
// PURPOSE: test MCP23S17 library
|
|
|
|
// URL: https://github.com/RobTillaart/MCP23S17
|
2022-01-07 14:23:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
#include "MCP23S17.h"
|
|
|
|
|
|
|
|
|
|
|
|
MCP23S17 MCP(10);
|
|
|
|
int rv = 0;
|
|
|
|
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println();
|
2023-12-24 09:27:25 -05:00
|
|
|
Serial.print("MCP23S17_LIB_VERSION: ");
|
2022-01-07 14:23:20 -05:00
|
|
|
Serial.println(MCP23S17_LIB_VERSION);
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
SPI.begin();
|
2024-01-20 08:18:06 -05:00
|
|
|
|
2022-01-07 14:23:20 -05:00
|
|
|
rv = MCP.begin();
|
2022-04-14 04:53:15 -04:00
|
|
|
Serial.println(rv ? "true" : "false");
|
2022-01-07 14:23:20 -05:00
|
|
|
|
2023-08-14 06:56:15 -04:00
|
|
|
rv = MCP.pinMode8(0, 0xFF);
|
2022-01-07 14:23:20 -05:00
|
|
|
Serial.println(rv);
|
|
|
|
rv = MCP.pinMode8(1, 0xFF);
|
|
|
|
Serial.println(rv);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.print("HWSPI: ");
|
|
|
|
Serial.println(MCP.usesHWSPI());
|
|
|
|
|
2023-12-24 09:27:25 -05:00
|
|
|
Serial.println("TEST read1(pin)");
|
2022-01-07 14:23:20 -05:00
|
|
|
for (int pin = 0; pin < 16; pin++)
|
|
|
|
{
|
2023-12-24 09:27:25 -05:00
|
|
|
int val = MCP.read1(pin);
|
2022-01-07 14:23:20 -05:00
|
|
|
Serial.print(val);
|
|
|
|
Serial.print(' ');
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
delay(1000);
|
2023-12-24 09:27:25 -05:00
|
|
|
Serial.println("TEST read1(pin)");
|
2022-01-07 14:23:20 -05:00
|
|
|
for (int pin = 0; pin < 16; pin++)
|
|
|
|
{
|
2023-12-24 09:27:25 -05:00
|
|
|
int val = MCP.read1(pin);
|
2022-01-07 14:23:20 -05:00
|
|
|
Serial.print(val);
|
|
|
|
Serial.print(' ');
|
|
|
|
delay(100);
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-14 06:56:15 -04:00
|
|
|
// -- END OF FILE --
|
2022-01-07 14:23:20 -05:00
|
|
|
|