GY-63_MS5611/libraries/MCP23008/examples/MCP23008_digitalWrite/MCP23008_digitalWrite.ino

92 lines
1.7 KiB
Arduino
Raw Normal View History

2022-01-10 06:51:36 -05:00
//
// FILE: MCP23008_digitalWrite.ino
// AUTHOR: Rob Tillaart
// DATE: 2019-10-14
// PUPROSE: test MCP23008 library
#include "MCP23008.h"
#include "Wire.h"
MCP23008 MCP(0x27);
void setup()
{
2023-12-10 08:28:53 -05:00
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("MCP23008_LIB_VERSION: ");
2022-01-10 06:51:36 -05:00
Serial.println(MCP23008_LIB_VERSION);
2023-12-10 08:28:53 -05:00
Serial.println();
delay(100);
2022-01-10 06:51:36 -05:00
Wire.begin();
MCP.begin();
2023-07-19 07:24:56 -04:00
pinMode(8, INPUT); // use pin8 to read back MCP.pin0
MCP.pinMode8(0x00); // 0 = output, 1 = input
MCP.write8(0xFF);
2022-01-10 06:51:36 -05:00
Wire.setClock(100000);
2023-07-19 07:24:56 -04:00
Serial.println("TEST digitalWrite(0) - note bitorder");
2022-01-10 06:51:36 -05:00
for (int i = 0; i < 8; i++)
{
2023-07-19 07:24:56 -04:00
MCP.digitalWrite(0, i % 2); // alternating HIGH/LOW
2022-01-10 06:51:36 -05:00
Serial.print(i % 2);
2023-07-19 07:24:56 -04:00
Serial.print(digitalRead(8)); // read back status.
2022-01-10 06:51:36 -05:00
Serial.print('\t');
delay(250);
}
2023-07-19 07:24:56 -04:00
MCP.digitalWrite(0, LOW);
2022-01-10 06:51:36 -05:00
Serial.println();
Serial.println();
2023-07-19 07:24:56 -04:00
Serial.println("TEST read back");
for (int pin = 0; pin < 8; pin++)
{
int val = MCP.digitalRead(pin);
Serial.print(val);
Serial.print('\t');
}
Serial.println();
Serial.println(MCP.read8(), HEX);
Serial.println();
Serial.println("TEST digitalWrite(pin) - note bitorder");
2022-01-10 06:51:36 -05:00
for (int pin = 0; pin < 8; pin++)
{
MCP.digitalWrite(pin, 1 - pin % 2); // alternating HIGH/LOW
Serial.print(1 - pin % 2);
Serial.print('\t');
}
Serial.println();
Serial.println();
2023-07-19 07:24:56 -04:00
Serial.println("TEST read back");
Serial.println(digitalRead(8));
2022-01-10 06:51:36 -05:00
for (int pin = 0; pin < 8; pin++)
{
int val = MCP.digitalRead(pin);
Serial.print(val);
Serial.print('\t');
}
Serial.println();
2023-07-19 07:24:56 -04:00
Serial.println(MCP.read8(), HEX);
2022-01-10 06:51:36 -05:00
Serial.println();
}
void loop()
{
}
// -- END OF FILE --