+/**
+ * @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 <Arduino.h>
+#include <Adafruit_MCP23X17.h>
+/* 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);
+ }
}