Rachele Didero's site Welcome to Rocky 96's HTMAA world

Welcome to Rocky96's
HTMAA world

A free, fully responsive (?) font of inspiration (?) designed by Rachele Didero for How to Make (Almost) Anything Course @ MIT Media Lab
and released for free .

November 15, 2023

Week 9

Output Devices

- LED that indicates the level of resistance -

BruGlove

Add an output device to a microcontroller board I've designed, program it to do something

For week number 8, "input devices," I created a glove capable of recognizing changes in the resistance of the conductive rubber cord placed on the index finger. To calculate this variation, I designed a Lilypad-style PCB board that I could then sew onto the knitted wrist of the glove.

The structure of the glove and the PCB board was already designed to also have an output in the glove: the LED of the XIAO RP-2040 changes color depending on the magnitude of the resistance applied to the conductive rubber cord on the index finger. With a resistance greater than 4500, the LED light is red. With a resistance less than 4500 and greater than 3500, the LED light is blue. With a resistance less than 3500, the LED light is green. I followed the following code that I generated using Chat GPT and by changing the resistance values:

Code to change XIAO led according to resistance change

i = 0;

const int resistorPin = A4;  // Analog pin connected to the resistor
const int ledPinRed = 17;    // Digital pin connected to the red LED
const int ledPinGreen = 16;  // Digital pin connected to the green LED
const int ledPinBlue = 25;   // Digital pin connected to the blue LED

void setup() {
  pinMode(resistorPin, INPUT);
  pinMode(ledPinRed, OUTPUT);
  pinMode(ledPinGreen, OUTPUT);
  pinMode(ledPinBlue, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int resistance = analogRead(resistorPin);

  // Print the resistance value to the serial monitor for debugging
  Serial.println("Resistance: " + String(resistance));

  if (resistance > 4500) {
    // High resistance, set LED to RED
    setColor(255, 0, 0);
  } else if (resistance > 3500) {
    // Medium resistance, set LED to BLUE
    setColor(0, 0, 255);
  } else {
    // Low resistance, set LED to GREEN
    setColor(0, 255, 0);
  }

  delay(500);  // Adjust the delay as needed
}

// Function to set the color of the RGB LED
void setColor(int red, int green, int blue) {
  analogWrite(ledPinRed, red);
  analogWrite(ledPinGreen, green);
  analogWrite(ledPinBlue, blue);
}


print 'It took ' + i + ' iterations to sort the deck.';

I haven't tested if the code works when connected to my glove yet, but I will do so as soon as I return from Brussels. I had an issue with the connections on the board, which has delayed my progress.


I had an issue with the connections on the board, which has delayed my progress.