Add code for several projects, remove test folder
This commit is contained in:
parent
e6b338d590
commit
f22327bd12
20 changed files with 709 additions and 3 deletions
|
|
@ -0,0 +1,61 @@
|
|||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define PIN 1
|
||||
#define NUM_LEDS 36
|
||||
|
||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN);
|
||||
|
||||
uint8_t mode = 0, // Current animation effect
|
||||
offset = 0; // Position of spinner animation
|
||||
uint32_t color = 0xA000A0; // Purple
|
||||
uint32_t prevTime; // Time of last animation mode switch
|
||||
|
||||
void setup() {
|
||||
pixels.begin();
|
||||
pixels.setBrightness(255); // Full brightness
|
||||
prevTime = millis(); // Starting time
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uint8_t i;
|
||||
uint32_t t;
|
||||
|
||||
switch(mode) {
|
||||
|
||||
case 0: // Random sparkles - just one LED on at a time!
|
||||
i = random(NUM_LEDS); // Choose a random pixel
|
||||
pixels.setPixelColor(i, color); // Set it to current color
|
||||
pixels.show(); // Refresh LED states
|
||||
// Set same pixel to "off" color now but DON'T refresh...
|
||||
// it stays on for now...both this and the next random
|
||||
// pixel will be refreshed on the next pass.
|
||||
pixels.setPixelColor(i, 0);
|
||||
delay(10); // 10 millisecond delay
|
||||
break;
|
||||
|
||||
case 1: // Spinny wheel
|
||||
for(i=0; i<NUM_LEDS; i++) { // For each LED...
|
||||
uint32_t c = 0; // Assume pixel will be "off" color
|
||||
if(((offset + i) & 7) < 2) { // For each 8 pixels, 2 will be...
|
||||
c = color; // ...assigned the current color
|
||||
}
|
||||
pixels.setPixelColor(i, c); // Set color of pixel 'i'
|
||||
}
|
||||
pixels.show(); // Refresh LED states
|
||||
delay(90); // 90 millisecond delay
|
||||
offset++; // Shift animation by 1 pixel on next frame
|
||||
break;
|
||||
|
||||
// More animation modes could be added here!
|
||||
}
|
||||
|
||||
t = millis(); // Current time in milliseconds
|
||||
if((t - prevTime) > 8000) { // Every 8 seconds...
|
||||
mode++; // Advance to next animation mode
|
||||
if(mode > 1) { // End of modes?
|
||||
mode = 0; // Start over from beginning
|
||||
}
|
||||
pixels.clear(); // Set all pixels to 'off' state
|
||||
prevTime = t; // Record the time of the last mode change
|
||||
}
|
||||
}
|
||||
47
Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.py
Normal file
47
Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import board
|
||||
import neopixel
|
||||
import time
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
numpix = 36 # Number of NeoPixels
|
||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1.0)
|
||||
|
||||
mode = 0 # Current animation effect
|
||||
offset = 0 # Position of spinner animation
|
||||
color = [160, 0, 160] # RGB color - purple
|
||||
prevtime = time.monotonic() # Time of last animation mode switch
|
||||
|
||||
while True: # Loop forever...
|
||||
|
||||
if mode == 0: # Random sparkles - lights just one LED at a time
|
||||
i = random.randint(0, numpix - 1) # Choose random pixel
|
||||
strip[i] = color # Set it to current color
|
||||
strip.write() # Refresh LED states
|
||||
# Set same pixel to "off" color now but DON'T refresh...
|
||||
# it stays on for now...bot this and the next random
|
||||
# pixel will be refreshed on the next pass.
|
||||
strip[i] = [0,0,0]
|
||||
time.sleep(0.008) # 8 millisecond delay
|
||||
elif mode == 1: # Spinny wheel (4 LEDs on at a time)
|
||||
for i in range(numpix): # For each LED...
|
||||
if ((offset + i) & 7) < 2: # 2 pixels out of 8...
|
||||
strip[i] = color # are set to current color
|
||||
else:
|
||||
strip[i] = [0,0,0] # other pixels are off
|
||||
strip.write() # Refresh LED states
|
||||
time.sleep(0.08) # 80 millisecond delay
|
||||
offset += 1 # Shift animation by 1 pixel on next frame
|
||||
if offset >= 8: offset = 0
|
||||
# Additional animation modes could be added here!
|
||||
|
||||
t = time.monotonic() # Current time in seconds
|
||||
if (t - prevtime) >= 8: # Every 8 seconds...
|
||||
mode += 1 # Advance to next mode
|
||||
if mode > 1: # End of modes?
|
||||
mode = 0 # Start over from beginning
|
||||
strip.fill([0,0,0]) # Turn off all pixels
|
||||
prevtime = t # Record time of last mode change
|
||||
4
Gemma_3D_Printed_Tree_Topper/README.md
Normal file
4
Gemma_3D_Printed_Tree_Topper/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Gemma_3D_Printed_Tree_Topper
|
||||
|
||||
Code to accompany this tutorial:
|
||||
https://learn.adafruit.com/gemma-3d-printed-tree-topper
|
||||
66
Mystical_LED_Halloween_Hood/Mystical_LED_Halloween_Hood.ino
Normal file
66
Mystical_LED_Halloween_Hood/Mystical_LED_Halloween_Hood.ino
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
//fades all pixels subtly
|
||||
//code by Tony Sherwood for Adafruit Industries
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define PIN 1
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = 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)
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(14, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
int alpha; // Current value of the pixels
|
||||
int dir = 1; // Direction of the pixels... 1 = getting brighter, 0 = getting dimmer
|
||||
int flip; // Randomly flip the direction every once in a while
|
||||
int minAlpha = 25; // Min value of brightness
|
||||
int maxAlpha = 100; // Max value of brightness
|
||||
int alphaDelta = 5; // Delta of brightness between times through the loop
|
||||
|
||||
void setup() {
|
||||
strip.begin();
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
}
|
||||
|
||||
void loop() {
|
||||
flip = random(32);
|
||||
if(flip > 20) {
|
||||
dir = 1 - dir;
|
||||
}
|
||||
// Some example procedures showing how to display to the pixels:
|
||||
if (dir == 1) {
|
||||
alpha += alphaDelta;
|
||||
}
|
||||
if (dir == 0) {
|
||||
alpha -= alphaDelta;
|
||||
}
|
||||
if (alpha < minAlpha) {
|
||||
alpha = minAlpha;
|
||||
dir = 1;
|
||||
}
|
||||
if (alpha > maxAlpha) {
|
||||
alpha = maxAlpha;
|
||||
dir = 0;
|
||||
}
|
||||
// Change the line below to alter the color of the lights
|
||||
// The numbers represent the Red, Green, and Blue values
|
||||
// of the lights, as a value between 0(off) and 1(max brightness)
|
||||
//
|
||||
// EX:
|
||||
// colorSet(strip.Color(alpha, 0, alpha/2)); // Pink
|
||||
//colorSet(strip.Color(0, 0, alpha)); // Blue
|
||||
//colorSet(strip.Color(alpha, alpha/2, 0)); // Yellow
|
||||
colorSet(strip.Color(alpha, 0, 0)); // Red
|
||||
}
|
||||
|
||||
// Fill the dots one after the other with a color
|
||||
void colorSet(uint32_t c) {
|
||||
for(uint16_t i=0; i<strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, c);
|
||||
strip.show();
|
||||
}
|
||||
}
|
||||
36
Mystical_LED_Halloween_Hood/Mystical_LED_Halloween_Hood.py
Normal file
36
Mystical_LED_Halloween_Hood/Mystical_LED_Halloween_Hood.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import board
|
||||
import neopixel
|
||||
import time
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
numpix = 17 # Number of NeoPixels
|
||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||
strip = neopixel.NeoPixel(pixpin, numpix)
|
||||
|
||||
minAlpha = 0.1 # Minimum brightness
|
||||
maxAlpha = 0.4 # Maximum brightness
|
||||
alpha = (minAlpha + maxAlpha) / 2 # Start in middle
|
||||
alphaDelta = 0.008 # Amount to change brightness each time through loop
|
||||
alphaUp = True # If True, brightness increasing, else decreasing
|
||||
|
||||
strip.fill([255, 0, 0]) # Fill red, or change to R,G,B of your liking
|
||||
|
||||
while True: # Loop forever...
|
||||
if random.randint(1, 5) == 5: # 1-in-5 random chance
|
||||
alphaUp = not alphaUp # of reversing direction
|
||||
if alphaUp: # Increasing brightness?
|
||||
alpha += alphaDelta # Add some amount
|
||||
if alpha >= maxAlpha: # At or above max?
|
||||
alpha = maxAlpha # Limit to max
|
||||
alphaUp = False # and switch direction
|
||||
else: # Else decreasing brightness
|
||||
alpha -= alphaDelta # Subtract some amount
|
||||
if alpha <= minAlpha: # At or below min?
|
||||
alpha = minAlpha # Limit to min
|
||||
alphaUp = True # and switch direction
|
||||
|
||||
strip.brightness = alpha # Set brightness to 0.0 to 1.0
|
||||
strip.write() # and issue data to LED strip
|
||||
4
Mystical_LED_Halloween_Hood/README.md
Normal file
4
Mystical_LED_Halloween_Hood/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Mystical_LED_Halloween_Hood
|
||||
|
||||
Code to accompany this tutorial:
|
||||
https://learn.adafruit.com/mystical-led-halloween-hood
|
||||
77
NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.ino
Normal file
77
NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.ino
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define NUM_LEDS 24 // 24 LED NeoPixel ring
|
||||
#define NEOPIXEL_PIN 0 // Pin D0 on Gemma
|
||||
#define VIBRATION_PIN 1 // Pin D1 on Gemma
|
||||
#define ANALOG_RANDOMNESS_PIN A1 // Not connected to anything
|
||||
|
||||
#define DEFAULT_FRAME_LEN 60
|
||||
#define MAX_FRAME_LEN 255
|
||||
#define MIN_FRAME_LEN 5
|
||||
#define COOLDOWN_AT 2000
|
||||
#define DIM_AT 2500
|
||||
#define BRIGHTNESS_HIGH 128
|
||||
#define BRIGHTNESS_LOW 32
|
||||
|
||||
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, NEOPIXEL_PIN);
|
||||
|
||||
uint32_t color = pixels.Color(0, 120, 30);
|
||||
uint8_t offset = 0;
|
||||
uint8_t frame_len = DEFAULT_FRAME_LEN;
|
||||
uint32_t last_vibration = 0;
|
||||
uint32_t last_frame = 0;
|
||||
|
||||
void setup() {
|
||||
// Random number generator is seeded from an unused 'floating'
|
||||
// analog input - this helps ensure the random color choices
|
||||
// aren't always the same order.
|
||||
randomSeed(analogRead(ANALOG_RANDOMNESS_PIN));
|
||||
// Enable pullup on vibration switch pin. When the switch
|
||||
// is activated, it's pulled to ground (LOW).
|
||||
pinMode(VIBRATION_PIN, INPUT_PULLUP);
|
||||
pixels.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uint32_t t;
|
||||
|
||||
// Compare millis() against lastFrame time to keep frame-to-frame
|
||||
// animation timing consistent. Use this idle time to check the
|
||||
// vibration switch for activity.
|
||||
while(((t = millis()) - last_frame) <= frame_len) {
|
||||
if(!digitalRead(VIBRATION_PIN)) { // Vibration sensor activated?
|
||||
color = pixels.Color( // Pick a random RGB color
|
||||
random(256), // red
|
||||
random(256), // green
|
||||
random(256) // blue
|
||||
);
|
||||
frame_len = DEFAULT_FRAME_LEN; // Reset frame timing to default
|
||||
last_vibration = t; // Save last vibration time
|
||||
}
|
||||
}
|
||||
|
||||
// Stretch out frames if nothing has happened in a couple of seconds:
|
||||
if((t - last_vibration) > COOLDOWN_AT) {
|
||||
if(++frame_len > MAX_FRAME_LEN) frame_len = MIN_FRAME_LEN;
|
||||
}
|
||||
|
||||
// If we haven't registered a vibration in DIM_AT ms, go dim:
|
||||
if((t - last_vibration) > DIM_AT) {
|
||||
pixels.setBrightness(BRIGHTNESS_LOW);
|
||||
} else {
|
||||
pixels.setBrightness(BRIGHTNESS_HIGH);
|
||||
}
|
||||
|
||||
// Erase previous pixels and light new ones:
|
||||
pixels.clear();
|
||||
for(int i=0; i<NUM_LEDS; i += 6) {
|
||||
pixels.setPixelColor((offset + i) % NUM_LEDS, color);
|
||||
}
|
||||
|
||||
pixels.show();
|
||||
|
||||
// Increase pixel offset until it hits 6, then roll back to 0:
|
||||
if(++offset == 6) offset = 0;
|
||||
|
||||
last_frame = t;
|
||||
}
|
||||
80
NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.py
Normal file
80
NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.py
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import board
|
||||
import digitalio
|
||||
import analogio
|
||||
import neopixel
|
||||
import time
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except:
|
||||
import random
|
||||
|
||||
num_leds = 24 # 24 LED NeoPixel ring
|
||||
neopixel_pin = board.D0 # Pin where NeoPixels are connected
|
||||
vibration_pin = board.D1 # Pin where vibration switch is connected
|
||||
analog_pin = board.A0 # Not connected to anything
|
||||
strip = neopixel.NeoPixel(neopixel_pin, num_leds)
|
||||
|
||||
default_frame_len = 0.06 # Time (in seconds) of typical animation frame
|
||||
max_frame_len = 0.25 # Gradually slows toward this
|
||||
min_frame_len = 0.005 # But sometimes as little as this
|
||||
cooldown_at = 2.0 # After this many seconds, start slowing down
|
||||
dim_at = 2.5 # After this many seconds, dim LEDs
|
||||
brightness_high = 0.5 # Active brightness
|
||||
brightness_low = 0.125 # Idle brightness
|
||||
|
||||
color = [0, 120, 30] # Initial LED color
|
||||
offset = 0 # Animation position
|
||||
frame_len = default_frame_len # Frame-to-frame time, seconds
|
||||
last_vibration = 0.0 # Time of last vibration
|
||||
last_frame = 0.0 # Time of last animation frame
|
||||
|
||||
# Random number generator is seeded from an unused 'floating'
|
||||
# analog input - this helps ensure the random color choices
|
||||
# aren't always the same order.
|
||||
pin = analogio.AnalogIn(analog_pin)
|
||||
random.seed(pin.value)
|
||||
pin.deinit()
|
||||
|
||||
# Set up digital pin for reading vibration switch
|
||||
pin = digitalio.DigitalInOut(vibration_pin)
|
||||
pin.direction = digitalio.Direction.INPUT
|
||||
pin.pull = digitalio.Pull.UP
|
||||
|
||||
while True: # Loop forever...
|
||||
|
||||
while True:
|
||||
# Compare time.monotonic() against last_frame to keep
|
||||
# frame-to-frame animation timing consistent. Use this
|
||||
# idle time to check the vibration switch for activity.
|
||||
t = time.monotonic()
|
||||
if t - last_frame >= frame_len: break
|
||||
if not pin.value: # Vibration switch activated?
|
||||
color = [ # Pick a random RGB color...
|
||||
random.randint(32, 255),
|
||||
random.randint(32, 255),
|
||||
random.randint(32, 255) ]
|
||||
frame_len = default_frame_len # Reset frame timing
|
||||
last_vibration = t # Save last trigger time
|
||||
|
||||
# Stretch out frames if nothing has happened in a couple of seconds:
|
||||
if((t - last_vibration) > cooldown_at):
|
||||
frame_len += 0.001 # Add 1 ms
|
||||
if frame_len > max_frame_len: frame_len = min_frame_len
|
||||
|
||||
# If we haven't registered a vibration in dim_at ms, go dim:
|
||||
if (t - last_vibration) > dim_at:
|
||||
strip.brightness = brightness_low
|
||||
else:
|
||||
strip.brightness = brightness_high
|
||||
|
||||
# Erase previous pixels and light new ones:
|
||||
strip.fill( [0, 0, 0] )
|
||||
for i in range(0, num_leds, 6):
|
||||
strip[(offset + i) % num_leds] = color
|
||||
|
||||
strip.write() # and issue data to LED strip
|
||||
|
||||
# Increase pixel offset until it hits 6, then roll back to 0:
|
||||
offset = (offset + 1) % 6
|
||||
|
||||
last_frame = t
|
||||
4
NeoPixel_Blinkendisc/README.md
Normal file
4
NeoPixel_Blinkendisc/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# NeoPixel_Blinkendisc
|
||||
|
||||
Code to accompany this tutorial:
|
||||
https://learn.adafruit.com/a-neopixel-blinkendisc
|
||||
37
NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.ino
Normal file
37
NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.ino
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//Figure-Eight animation for Neopixel Ring Bangle Bracelet
|
||||
//By Dano Wall and Becky Stern for Adafruit Industries
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define PIN 1 // Marked D1 on GEMMA
|
||||
#define NUM_LEDS 64
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = pin number (most are valid)
|
||||
// Parameter 3 = pixel type:
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB);
|
||||
|
||||
uint32_t color = strip.Color(5, 250, 200); // Change RGB color value here
|
||||
|
||||
// Array of pixels in order of animation - 70 in total:
|
||||
int sine[] = {
|
||||
4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
||||
36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60,
|
||||
61, 62, 63, 48, 49, 50, 51, 52, 44, 43, 42, 41, 40, 39, 38, 37, 36, 28,
|
||||
29, 30, 31, 16, 17, 18, 19, 20, 12, 11, 10, 9, 8, 7, 6, 5 };
|
||||
|
||||
void setup() {
|
||||
strip.begin();
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
strip.setBrightness(40); // 40/255 brightness (about 15%)
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for(int i=0; i<70; i++) {
|
||||
strip.setPixelColor(sine[i], 0); // Erase 'tail'
|
||||
strip.setPixelColor(sine[(i + 10) % 70], color); // Draw 'head' pixel
|
||||
strip.show();
|
||||
delay(60);
|
||||
}
|
||||
}
|
||||
27
NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py
Normal file
27
NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import board
|
||||
import neopixel
|
||||
import time
|
||||
try:
|
||||
import urandom as random
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
numpix = 64 # Number of NeoPixels
|
||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15)
|
||||
color = [5, 250, 200] # RGB color - cyan
|
||||
|
||||
sine = [ # These are the pixels in order of animation - 70 pixels in total:
|
||||
4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
||||
36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60,
|
||||
61, 62, 63, 48, 49, 50, 51, 52, 44, 43, 42, 41, 40, 39, 38, 37, 36, 28,
|
||||
29, 30, 31, 16, 17, 18, 19, 20, 12, 11, 10, 9, 8, 7, 6, 5 ]
|
||||
|
||||
while True: # Loop forever...
|
||||
for i in range(len(sine)):
|
||||
# Erase 'tail':
|
||||
strip[sine[i]] = [0,0,0]
|
||||
# Draw 'head,' 10 pixels ahead:
|
||||
strip[sine[(i + 10) % len(sine)]] = color
|
||||
strip.write() # Refresh LED states
|
||||
time.sleep(0.04) # 40 millisecond delay
|
||||
4
NeoPixel_Ring_Bangle_Bracelet/README.md
Normal file
4
NeoPixel_Ring_Bangle_Bracelet/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# NeoPixel_Ring_Bangle_Bracelet
|
||||
|
||||
Code to accompany this tutorial:
|
||||
https://learn.adafruit.com/neopixel-ring-bangle-bracelet
|
||||
69
NeoPixel_Ring_Bangle_Bracelet/Random_Flash.ino
Normal file
69
NeoPixel_Ring_Bangle_Bracelet/Random_Flash.ino
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
//Random Flash animation for Neopixel Ring Bangle Bracelet
|
||||
//by Dano Wall and Becky Stern for Adafruit Industries
|
||||
//based on the Sparkle Skirt, minus the accelerometer
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define PIN 1 // Marked D1 on GEMMA
|
||||
#define NUM_LEDS 64
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = pin number (most are valid)
|
||||
// Parameter 3 = pixel type:
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB);
|
||||
|
||||
// Here is where you can put in your favorite colors that will appear!
|
||||
// just add new {nnn, nnn, nnn}, lines. They will be picked out randomly
|
||||
uint8_t myColors[][3] = {
|
||||
{232, 100, 255}, // purple
|
||||
{200, 200, 20}, // yellow
|
||||
{ 30, 200, 200}, // blue
|
||||
};
|
||||
|
||||
// don't edit the line below
|
||||
#define FAVCOLORS sizeof(myColors) / 3
|
||||
|
||||
void setup() {
|
||||
strip.begin();
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
strip.setBrightness(40); // 40/255 brightness (about 15%)
|
||||
}
|
||||
|
||||
void loop() {
|
||||
flashRandom(5); // Number is 'wait' delay, smaller num = faster twinkle
|
||||
}
|
||||
|
||||
void flashRandom(int wait) {
|
||||
|
||||
// pick a random favorite color!
|
||||
int c = random(FAVCOLORS);
|
||||
int red = myColors[c][0];
|
||||
int green = myColors[c][1];
|
||||
int blue = myColors[c][2];
|
||||
|
||||
// get a random pixel from the list
|
||||
int j = random(strip.numPixels());
|
||||
|
||||
// now we will fade in over 5 steps
|
||||
for (int x=1; x <= 5; x++) {
|
||||
int r = red * x / 5;
|
||||
int g = green * x / 5;
|
||||
int b = blue * x / 5;
|
||||
|
||||
strip.setPixelColor(j, strip.Color(r, g, b));
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
// & fade out in 5 steps
|
||||
for (int x=5; x >= 0; x--) {
|
||||
int r = red * x / 5;
|
||||
int g = green * x / 5;
|
||||
int b = blue * x / 5;
|
||||
|
||||
strip.setPixelColor(j, strip.Color(r, g, b));
|
||||
strip.show();
|
||||
delay(wait);
|
||||
}
|
||||
// LED will be off when done (they are faded to 0)
|
||||
}
|
||||
28
NeoPixel_Ring_Bangle_Bracelet/Random_Flash.py
Normal file
28
NeoPixel_Ring_Bangle_Bracelet/Random_Flash.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import board
|
||||
import neopixel
|
||||
import time
|
||||
try:
|
||||
import urandom as random
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
numpix = 64 # Number of NeoPixels
|
||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.0)
|
||||
colors = [
|
||||
[ 232, 100, 255 ], # Purple
|
||||
[ 200, 200, 20 ], # Yellow
|
||||
[ 30, 200, 200 ], # Blue
|
||||
]
|
||||
|
||||
while True: # Loop forever...
|
||||
c = random.randint(0, len(colors) - 1) # Choose random color index
|
||||
j = random.randint(0, numpix - 1) # Choose random pixel
|
||||
strip[j] = colors[c] # Set pixel to color
|
||||
for i in range(1, 5):
|
||||
strip.brightness = i / 5.0 # Ramp up brightness
|
||||
strip.write()
|
||||
for i in range(5, 0, -1):
|
||||
strip.brightness = i / 5.0 # Ramp down brightness
|
||||
strip.write()
|
||||
strip[j] = [0,0,0] # Set pixel to 'off'
|
||||
35
NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.ino
Normal file
35
NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.ino
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//Basic sine wave animation for NeoPixel Ring Bangle Bracelet
|
||||
//by Dano Wall and Becky Stern for Adafruit Industries
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define PIN 1 // Marked D1 on GEMMA
|
||||
#define NUM_LEDS 64
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = pin number (most are valid)
|
||||
// Parameter 3 = pixel type:
|
||||
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
|
||||
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB);
|
||||
|
||||
uint32_t color = strip.Color(75, 250, 100); // Change RGB color value here
|
||||
|
||||
// These are the pixels in order of animation-- 36 pixels in total:
|
||||
int sine[] = {
|
||||
4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
||||
36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60 };
|
||||
|
||||
void setup() {
|
||||
strip.begin();
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
strip.setBrightness(40); // 40/255 brightness (about 15%)
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for(int i=0; i<36; i++) {
|
||||
strip.setPixelColor(sine[i], color); // Draw 'head' pixel
|
||||
strip.setPixelColor(sine[(i + 36 - 8) % 36], 0); // Erase 'tail'
|
||||
strip.show();
|
||||
delay(40);
|
||||
}
|
||||
}
|
||||
25
NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py
Normal file
25
NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import board
|
||||
import neopixel
|
||||
import time
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
numpix = 64 # Number of NeoPixels
|
||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15)
|
||||
color = [75, 250, 100] # RGB color - teal
|
||||
|
||||
sine = [ # These are the pixels in order of animation - 36 pixels in total:
|
||||
4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
||||
36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60 ]
|
||||
|
||||
while True: # Loop forever...
|
||||
for i in range(len(sine)):
|
||||
# Set 'head' pixel to color:
|
||||
strip[sine[i]] = color
|
||||
# Erase 'tail,' 8 pixels back:
|
||||
strip[sine[(i + len(sine) - 8) % len(sine)]] = [0,0,0]
|
||||
strip.write() # Refresh LED states
|
||||
time.sleep(0.016) # 16 millisecond delay
|
||||
4
Superhero_Power_Plant/README.md
Normal file
4
Superhero_Power_Plant/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Superhero_Power_Plant
|
||||
|
||||
Code to accompany this tutorial:
|
||||
https://learn.adafruit.com/superhero-power-plant
|
||||
65
Superhero_Power_Plant/Superhero_Power_Plant.ino
Normal file
65
Superhero_Power_Plant/Superhero_Power_Plant.ino
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//Superhero Power Plant
|
||||
//fades all pixels subtly
|
||||
//code by Tony Sherwood for Adafruit Industries
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#define PIN 1
|
||||
|
||||
// Parameter 1 = number of pixels in strip
|
||||
// Parameter 2 = 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)
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(17, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
int alpha; // Current value of the pixels
|
||||
int dir = 1; // Direction of the pixels... 1 = getting brighter, 0 = getting dimmer
|
||||
int flip; // Randomly flip the direction every once in a while
|
||||
int minAlpha = 25; // Min value of brightness
|
||||
int maxAlpha = 100; // Max value of brightness
|
||||
int alphaDelta = 5; // Delta of brightness between times through the loop
|
||||
|
||||
void setup() {
|
||||
strip.begin();
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
}
|
||||
|
||||
void loop() {
|
||||
flip = random(32);
|
||||
if(flip > 20) {
|
||||
dir = 1 - dir;
|
||||
}
|
||||
// Some example procedures showing how to display to the pixels:
|
||||
if (dir == 1) {
|
||||
alpha += alphaDelta;
|
||||
}
|
||||
if (dir == 0) {
|
||||
alpha -= alphaDelta;
|
||||
}
|
||||
if (alpha < minAlpha) {
|
||||
alpha = minAlpha;
|
||||
dir = 1;
|
||||
}
|
||||
if (alpha > maxAlpha) {
|
||||
alpha = maxAlpha;
|
||||
dir = 0;
|
||||
}
|
||||
// Change the line below to alter the color of the lights
|
||||
// The numbers represent the Red, Green, and Blue values
|
||||
// of the lights, as a value between 0(off) and 1(max brightness)
|
||||
//
|
||||
// EX:
|
||||
// colorWipe(strip.Color(alpha, 0, alpha/2)); // Pink
|
||||
colorWipe(strip.Color(0, 0, alpha)); // Blue
|
||||
}
|
||||
|
||||
// Fill the dots one after the other with a color
|
||||
void colorWipe(uint32_t c) {
|
||||
for(uint16_t i=0; i<strip.numPixels(); i++) {
|
||||
strip.setPixelColor(i, c);
|
||||
strip.show();
|
||||
}
|
||||
}
|
||||
36
Superhero_Power_Plant/Superhero_Power_Plant.py
Normal file
36
Superhero_Power_Plant/Superhero_Power_Plant.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import board
|
||||
import neopixel
|
||||
import time
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except ImportError:
|
||||
import random
|
||||
|
||||
numpix = 17 # Number of NeoPixels
|
||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||
strip = neopixel.NeoPixel(pixpin, numpix)
|
||||
|
||||
minAlpha = 0.1 # Minimum brightness
|
||||
maxAlpha = 0.4 # Maximum brightness
|
||||
alpha = (minAlpha + maxAlpha) / 2 # Start in middle
|
||||
alphaDelta = 0.01 # Amount to change brightness each time through loop
|
||||
alphaUp = True # If True, brightness increasing, else decreasing
|
||||
|
||||
strip.fill([0, 0, 255]) # Fill blue, or change to R,G,B of your liking
|
||||
|
||||
while True: # Loop forever...
|
||||
if random.randint(1, 5) == 5: # 1-in-5 random chance
|
||||
alphaUp = not alphaUp # of reversing direction
|
||||
if alphaUp: # Increasing brightness?
|
||||
alpha += alphaDelta # Add some amount
|
||||
if alpha >= maxAlpha: # At or above max?
|
||||
alpha = maxAlpha # Limit to max
|
||||
alphaUp = False # and switch direction
|
||||
else: # Else decreasing brightness
|
||||
alpha -= alphaDelta # Subtract some amount
|
||||
if alpha <= minAlpha: # At or below min?
|
||||
alpha = minAlpha # Limit to min
|
||||
alphaUp = True # and switch direction
|
||||
|
||||
strip.brightness = alpha # Set brightness to 0.0 to 1.0
|
||||
strip.write() # and issue data to LED strip
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
Testing 1 2 3
|
||||
Look at this code
|
||||
Look at it!
|
||||
Loading…
Reference in a new issue