2021-01-29 06:31:58 -05:00
|
|
|
//
|
2022-01-09 14:53:12 -05:00
|
|
|
// FILE: MCP23017_digitalWrite.ino
|
2021-01-29 06:31:58 -05:00
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2019-10-14
|
|
|
|
// PUPROSE: test MCP23017 library
|
|
|
|
|
|
|
|
|
|
|
|
#include "MCP23017.h"
|
|
|
|
#include "Wire.h"
|
|
|
|
|
|
|
|
|
|
|
|
MCP23017 MCP(0x27);
|
|
|
|
|
2021-12-21 11:12:20 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(230400);
|
|
|
|
Serial.print("MCP23017_test version: ");
|
|
|
|
Serial.println(MCP23017_LIB_VERSION);
|
|
|
|
|
|
|
|
Wire.begin();
|
|
|
|
|
|
|
|
MCP.begin();
|
|
|
|
|
|
|
|
MCP.pinMode8(0, 0x00); // 0 = output , 1 = input
|
|
|
|
MCP.pinMode8(1, 0x00);
|
|
|
|
Wire.setClock(50);
|
|
|
|
|
|
|
|
Serial.println("TEST digitalWrite(0)");
|
|
|
|
for (int i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
MCP.digitalWrite(0, i % 2); // alternating HIGH/LOW
|
|
|
|
Serial.print(i % 2);
|
|
|
|
Serial.print('\t');
|
|
|
|
delay(250);
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
Serial.println("TEST digitalWrite(pin)");
|
|
|
|
for (int pin = 0; pin < 16; pin++)
|
|
|
|
{
|
|
|
|
MCP.digitalWrite(pin, 1 - pin % 2); // alternating HIGH/LOW
|
|
|
|
Serial.print(1 - pin % 2);
|
|
|
|
Serial.print('\t');
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
Serial.println("TEST read back");
|
|
|
|
|
|
|
|
for (int pin = 0; pin < 16; pin++)
|
|
|
|
{
|
|
|
|
int val = MCP.digitalRead(pin);
|
|
|
|
Serial.print(val);
|
|
|
|
Serial.print('\t');
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
|
2021-12-21 11:12:20 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-12-21 11:12:20 -05:00
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|