Light Up Glove
The art project I created is a series of lights
that respond to two pressure sensors within the glove. These two sensors
control lights on the thump and lights on the top of the fist. If
triggered sensor one will change neopixles on the thumb from a rainbow
pattern to flash blue lights, while sensor two will turn off the light
on the fist and have them flash in a pattern.
Arduino Code:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 10
#define MIC_PIN A0 // Pressure sensor here
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic ‘v1’ (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 – 500 Ohm resistor on first pixel’s data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit…if you must, connect GND first.
int soundLevel;
int lvl = 10;
int ledPins[] = { 2, 3, 4, 5, 6 ,7, 8,9};
//An array to hold the pin each led is connected to
int sensorPin = A1; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
void setup()
{
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
for (int i = 0; i< 8; i++) // loop repeating eight times
{
pinMode(ledPins[i], OUTPUT ); // turns i ledPin on
}
Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to ‘off’
}
void loop()
{
// Some example procedures showing how to display to the pixels:
// colorWipe(strip.Color(255, 0, 0), 50); // Red
//colorWipe(strip.Color(0, 255, 0), 50); // Green
//colorWipe(strip.Color(0, 0, 255), 50); // Blue
//colorWipe(strip.Color(0, 0, 0, 255), 50); // White RGBW
// Send a theater pixel chase in…
// theaterChase(strip.Color(127, 127, 127), 50); // White
soundLevel = analogRead(MIC_PIN); // Raw reading from mic
lvl = ((lvl * 7) + soundLevel) >> 3; // “Dampened” reading (else looks twitchy)
Serial.print(“Level: “);
Serial.println(lvl);
lvl = constrain(lvl , 0, 60);
sensorValue = constrain(sensorValue , 50 , 100);
// Serial.println(lvl);
// theaterChase(strip.Color(127, 0, 0), 50); // Red
theaterChase(strip.Color(0, 0, 127), 50); // Blue
oneAfterAnotherNoLoop();
sensorValue = analogRead(sensorPin);
Serial.println (sensorValue);
//rainbow(20);
//rainbowCycle(20);
//theaterChaseRainbow(50);
}
//THis will turn on each led one by one then turn off
void oneAfterAnotherNoLoop()
{
if ( sensorValue < 70)
{
int delayTime = 100;
//digitalWrite (ledPins[0], HIGH);
//turns LED pin 0 on, which is connected to led Pin 2
delay (delayTime);
for (int i = 0; i< 8; i++)
{
digitalWrite(ledPins[i], HIGH); // turns on led 7
delay (delayTime);
//turns led off
digitalWrite (ledPins[i],LOW); //turns lef 7 oss
delay (delayTime);
}
}
else
{
for (int i = 0; i< 8; i++)
{
digitalWrite(ledPins[i], HIGH); // turns on led
}
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait)
{
if (lvl < 30)
{
for (int j=0; j<10; j++)
{ //do 10 cycles of chasing
for (int q=0; q < 3; q++)
{
for (uint16_t i=0; i < strip.numPixels(); i=i+3)
{
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3)
{
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
if ( (lvl > 30) && ( lvl < 50))
for(uint16_t i=0; i<strip.numPixels(); i++) // wipe forwards
{
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
for(uint16_t i=strip.numPixels(); i>0; i–) // wipe backwards
{
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}