//Fabricademy Bootcamp 2026 at Creative Spark Dundalk //E-Textiles workshop, 27th May // //Connect a soft switch between pin A2 (aka D2) and GND on a Fabrixiao board with a Seeed Studio XIAO ESP32C3 microcontroller //Connect an LED 'noodle' or any kind of LED and a resistor between pin D6 and GND //The resistor value depends on what kind of LED you're using, but 330 Ohms will work for most // //Fabrixiao documentation: https://fabacademy.org/2020/labs/leon/students/adrian-torres/fabrixiao.html //Documentation on LED noodles: https://learn.adafruit.com/noods-uberguide/overview // //When powered on, or rebooted, the LED noodle lights up, whether or not the switch is included in the circuit. //Pressing the switch will toggle it off and on again //After 60 seconds of inactivity, the board will go into 'deep sleep', switching off the LED noodle and the onboard (blue) LED //Pressing the reset (R) button reboots the board, waking it up from deep sleep. // //Adapted by Jessica Stanley to add the sleep mode, from code from a Fab26 workshop by Anastasia Pistofidou and Adrian Torres. #include "esp_sleep.h" //Sleep modes library to enable the board to go to sleep const int sensePin = D2; //We attach a soft switch to this pin const int ledPin = D6; //Attach an LED 'noodle' or other LED to this pin, in series with a resistors const int statusLED = D10; //Onboard LED on the Fabrixiao bool ledState = true; // start with the LED on unsigned long lastActivityTime; //Checking how long it has been since the last button press const unsigned long sleepDelay = 60000; //Go to sleep after 60 seconds unsigned long lastPressTime = 0; //Checking when the button was last pressed, for debouncing const unsigned long minPressGap = 300; // Time in ms to wait between registering button presses void setup() { pinMode(ledPin, OUTPUT); pinMode(statusLED, OUTPUT); pinMode(sensePin, INPUT_PULLUP); //Activate the built-in pullup resistor to avoid floating input digitalWrite(ledPin, ledState); //Turn the LED strip on digitalWrite(statusLED, HIGH); //Turn the onboard LED on delay(200); // allow input to settle lastActivityTime = millis(); //Log the current time } // --- Debouncing: avoiding registering one button press as multiple --- bool buttonPressed() { if (digitalRead(sensePin) == LOW) { delay(80); // longer debounce if (digitalRead(sensePin) == LOW) { //if the button is currently being pressed // prevent rapid retriggers if (millis() - lastPressTime < minPressGap) return false; while (digitalRead(sensePin) == LOW); // wait for the switch to be released lastPressTime = millis(); //update the last time since the button was pressed return true; } } return false; } void loop() { //Toggle the LED if a new button press is registered //You could update this part to if (buttonPressed()) { ledState = !ledState; digitalWrite(ledPin, ledState); lastActivityTime = millis(); } //Send the board into deep sleep if 60s has elapsed if (millis() - lastActivityTime > sleepDelay) { //Flicker the LED strip three times to indicate that sleep mode is starting for (int i = 0; i < 3; i++) { digitalWrite(ledPin, HIGH); delay(100); digitalWrite(ledPin, LOW); delay(100); } esp_deep_sleep_start(); //start deep sleep! } delay(2); }