]> Devi Nivas Git - gt-ece4180-lab02.git/commitdiff
Finish IO Exapnder
authorAdvaith Menon <83835839+advaithm582@users.noreply.github.com>
Tue, 16 Sep 2025 21:40:09 +0000 (17:40 -0400)
committerAdvaith Menon <83835839+advaithm582@users.noreply.github.com>
Tue, 16 Sep 2025 21:40:09 +0000 (17:40 -0400)
* 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

index 74f966a4e2fe85eb6097ef342c3d3f2633e66ad8..1cd59a7184069850e45ce7cda82dae94e0ef6b22 100644 (file)
@@ -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 <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);
+    }
 }