Hello,
I wrote this sketch from the tutorial from tronixstuff : Adding an MCP23017 I/O Extender to Arduino or ESP8266 https://www.instructables.com/Adding-an-MCP23017-IO-Extender-to-Arduino-or-ESP82/
The sketch is below.
When I use the button with a pull-down or a pull-up resistor, all is working well.
Without pull-down or pull-up resistor, obviously, I have a floating problem.
Since my welds are already done (I was planning to use the Adafruit_MCP23017.h library), I would like to insert a pull-up like "mcp.pullUp (buttonPlay1Pin, HIGH);" or a pull-down.
My question : Is there a way to put all my buttons in pull-up (or pull-down) by default?
Thanks
#include <Wire.h> // Wire.h
byte input = 0;
void setup()
{
Serial.begin(9600);
Wire.begin(); // wake up I2C bus
Wire.beginTransmission(0x20);
Wire.write(0x00); // IODIRA register
Wire.write(0x00); // set entire PORT A as output
Wire.endTransmission();
}
void loop()
{
// read the inputs of PORT B
Wire.beginTransmission(0x20);
Wire.write(0x13);
Wire.endTransmission();
Wire.requestFrom(0x20, 1);
input = Wire.read();
Serial.print("input, DEC : "); Serial.println(input, DEC); // debug
// if PUSH BUTTON GPB6 (2) »» write LED GPA6 (64) ON
if (input == 2) { // GPB6 (2) Button
// write that input to PORT A
Wire.beginTransmission(0x20);
Wire.write(0x12);
Wire.write(64); // LED ON (GPA6)
Wire.endTransmission();
delay(100); // for debounce
Serial.println("LED ON"); // debug
delay(1000);
Wire.beginTransmission(0x20);
Wire.write(0x12);
Wire.write(00000000); // ALL LEDS OFF
Wire.endTransmission();
delay(100); // for debounce
Serial.println("ALL LEDS OFF"); // debug
}
}