Add pixel heart code
This commit is contained in:
parent
fb57acb40c
commit
d224d608f4
2 changed files with 61 additions and 0 deletions
|
|
@ -0,0 +1,33 @@
|
|||
#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);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import board
|
||||
import neopixel
|
||||
import digitalio
|
||||
import time
|
||||
|
||||
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
|
||||
Loading…
Reference in a new issue