From e163ea102b9fbb3b18ac42dd2912d04d39886a21 Mon Sep 17 00:00:00 2001 From: Advaith Menon <83835839+advaithm582@users.noreply.github.com> Date: Tue, 16 Sep 2025 17:40:09 -0400 Subject: [PATCH] Finish IO Exapnder * Pin numbers are hardcoded into ESP32 lib code * https://forum.arduino.cc/t/spi-interface-on-waveshare-esp32-c6-wroom-1/1344461 has more info on above topic. --- 01-IOExpanderSPI/01-IOExpanderSPI.ino | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/01-IOExpanderSPI/01-IOExpanderSPI.ino b/01-IOExpanderSPI/01-IOExpanderSPI.ino index 74f966a..1cd59a7 100644 --- a/01-IOExpanderSPI/01-IOExpanderSPI.ino +++ b/01-IOExpanderSPI/01-IOExpanderSPI.ino @@ -1,6 +1,41 @@ +/** + * @file 01-IOExpander.ino + * @author Advaith Menon, Anish Gajula, Lila Phonekeo + * @version 2025.09.16 + * @brief Control an LED over the I/O expander. + */ +#include +#include +/* hardcoded into the library, can't change */ +#define CS_PIN 18 +#define MOSI_PIN 19 +#define MISO_PIN 20 +#define SCK_PIN 21 +#define SDA_PIN 23 +#define SCL_PIN 22 + +#define BUTT_VPIN 8 +#define LED_VPIN 0 + +/** MCP instance */ +Adafruit_MCP23X17 io_expander; void setup() { + Serial.begin(9600); + /* Set up the I/O expander on the given pins */ + io_expander.begin_SPI(CS_PIN); + if (!io_expander.begin_SPI(CS_PIN)) { + while(1) + Serial.println("ERROR"); + } + io_expander.pinMode(BUTT_VPIN, INPUT); + io_expander.pinMode(LED_VPIN, OUTPUT); } void loop() { + if (io_expander.digitalRead(BUTT_VPIN)) { + io_expander.digitalWrite(LED_VPIN, 1); + } else { + io_expander.digitalWrite(LED_VPIN, 0); + } } -- 2.47.3