Wear your heart on your sleeve! Or at least on your lapel. This light-up heart display uses a light-dependent resistor and GEMMA, Adafruit's tiny wearable electronics platform.
Page last edited February 13, 2014
Text editor powered by tinymce.
Wear your heart on your sleeve! Or at least on your lapel. This light-up heart display uses a light-dependent resistor and GEMMA, Adafruit's tiny wearable electronics platform.
Page last edited February 13, 2014
Text editor powered by tinymce.
Plug in the USB cable and test out the pixels using the strandtest sketch included in the Adafruit NeoPixel library for Arduino (change the value of PIN to 1 before compiling).
Are they all working? Great! If not, unplug and re-evaluate your circuit. Clean up any frayed or loose bits of thread, re-stitch any loose spots and double-seal your knots. Probe again with your multimeter before reconnecting via USB.
If you're happy with the flashing lights, you're done! Sew your new circuit swatch into a brooch or onto your Valentine's outfit, and rock your new flashy accessory.
But if you want your heart to turn on only when the moment's right, continue on to add a light sensor, perfect for revealing your heart from under a jacket, hat, or hemline.
The circuit isn’t finished yet, but let’s get the final code onto the board before continuing, so we can test it along the way…
Page last edited February 13, 2014
Text editor powered by tinymce.
If this is your first time using GEMMA, work through the Introducing GEMMA guide first; you need to customize some settings in the Arduino IDE. Once you have it up and running (test the 'blink' sketch), then follow the instructions on the following page for installing the NeoPixel library:
Plug in your circuit and load up the sketch below:
// SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Adafruit_NeoPixel.h> #define NUM_LEDS 8 // This many NeoPixels... #define LED_PIN 1 // are connected to this DIGITAL pin # #define SENSOR 2 // Light sensor to this DIGITAL pin # Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN); void setup() { strip.begin(); strip.show(); // Initialize all pixels to 'off' pinMode(SENSOR, INPUT_PULLUP); // Enable pull-up resistor on sensor pin } void loop() { // The LDR is being used as a digital (binary) sensor, so it must be // COMPLETELY dark to turn it off, your finger is not opaque enough! if(!digitalRead(SENSOR)) { // Sensor exposed to light? colorWipe(strip.Color(255, 0, 255), 50); // Animate purple } else { // else sensor is dark colorWipe(strip.Color(0, 0, 0), 50); // Animate off } delay(2); // Pause 2 ms before repeating } // Fill pixels one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } }
// SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Adafruit_NeoPixel.h> #define NUM_LEDS 8 // This many NeoPixels... #define LED_PIN 1 // are connected to this DIGITAL pin # #define SENSOR 2 // Light sensor to this DIGITAL pin # Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN); void setup() { strip.begin(); strip.show(); // Initialize all pixels to 'off' pinMode(SENSOR, INPUT_PULLUP); // Enable pull-up resistor on sensor pin } void loop() { // The LDR is being used as a digital (binary) sensor, so it must be // COMPLETELY dark to turn it off, your finger is not opaque enough! if(!digitalRead(SENSOR)) { // Sensor exposed to light? colorWipe(strip.Color(255, 0, 255), 50); // Animate purple } else { // else sensor is dark colorWipe(strip.Color(0, 0, 0), 50); // Animate off } delay(2); // Pause 2 ms before repeating } // Fill pixels one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } }
Page last edited February 13, 2014
Text editor powered by tinymce.
GEMMA M0 boards can run CircuitPython — a different approach to programming compared to Arduino sketches. In fact, CircuitPython comes factory pre-loaded on GEMMA M0. If you’ve overwritten it with an Arduino sketch, or just want to learn the basics of setting up and using CircuitPython, this is explained in the Adafruit GEMMA M0 guide.
Below is CircuitPython code that works similarly (though not exactly the same) as the Arduino sketch shown on a prior page. To use this, plug the GEMMA M0 into USB…it should show up on your computer as a small flash drive…then edit the file “main.py” with your text editor of choice. Select and copy the code below and paste it into that file, entirely replacing its contents (don’t mix it in with lingering bits of old code). When you save the file, the code should start running almost immediately (if not, see notes at the bottom of this page).
If GEMMA M0 doesn’t show up as a drive, follow the GEMMA M0 guide link above to prepare the board for CircuitPython.
This code requires the neopixel.py library. A factory-fresh board will have this already installed. If you’ve just reloaded the board with CircuitPython, create the “lib” directory and then download neopixel.py from Github.
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board import digitalio import neopixel numpix = 8 # Number of NeoPixels ledpin = board.D1 # Digital pin # where NeoPixels are connected sensorpin = board.D2 # Digital pin # where light sensor is connected strip = neopixel.NeoPixel(ledpin, numpix, brightness=1.0) # Enable internal pullup resistor on sensor pin pin = digitalio.DigitalInOut(sensorpin) pin.direction = digitalio.Direction.INPUT pin.pull = digitalio.Pull.UP while True: # Loop forever... # LDR is being used as a digital (binary) sensor. It must be # completely dark to turn it off, a finger may not be opaque enough! if pin.value: color = (0, 0, 0) # Off else: color = (255, 0, 255) # Purple for i in range(numpix): # For each pixel... strip[i] = color # Set to 'color' strip.write() # Push data to pixels time.sleep(0.05) # Pause 50 ms time.sleep(0.002) # Pause 2 ms
# SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries # # SPDX-License-Identifier: MIT import time import board import digitalio import neopixel numpix = 8 # Number of NeoPixels ledpin = board.D1 # Digital pin # where NeoPixels are connected sensorpin = board.D2 # Digital pin # where light sensor is connected strip = neopixel.NeoPixel(ledpin, numpix, brightness=1.0) # Enable internal pullup resistor on sensor pin pin = digitalio.DigitalInOut(sensorpin) pin.direction = digitalio.Direction.INPUT pin.pull = digitalio.Pull.UP while True: # Loop forever... # LDR is being used as a digital (binary) sensor. It must be # completely dark to turn it off, a finger may not be opaque enough! if pin.value: color = (0, 0, 0) # Off else: color = (255, 0, 255) # Purple for i in range(numpix): # For each pixel... strip[i] = color # Set to 'color' strip.write() # Push data to pixels time.sleep(0.05) # Pause 50 ms time.sleep(0.002) # Pause 2 ms
Page last edited February 13, 2014
Text editor powered by tinymce.
Let's test before finishing the sewing. Use alligator clips to connect one leg of the photocell to D0 on GEMMA and the other to GND.
The pixels should animate pink when the sensor is exposed to light. Likewise they should turn off when the sensor is covered and completely dark.
To attach the LDR permanently, twist the ends of the leads into spirals as shown and paint the straight parts with nail polish-- it will insulate the LDR from the traces of conductive thread.
Stitch one spiral to the GND line around the inner perimeter of the heart (all GNDs are connected), and the other to D0 on GEMMA.
Toe knots and seal as before, then clip tails.
Page last edited February 13, 2014
Text editor powered by tinymce.
Page last edited February 13, 2014
Text editor powered by tinymce.
NeoPixels are chained together with data input coming from GEMMA D1, all + to Vout and all - to GND.
Photoresistor is attached to D2 and GND.
Page last edited February 13, 2014
Text editor powered by tinymce.