Skip to content

Commit 6e318fe

Browse files
authored
Add files via upload
1 parent 2e72954 commit 6e318fe

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-FileCopyrightText: 2017 Phillip Burgess for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
// Low power NeoPixel earrings example. Makes a nice blinky display
6+
// with just a few LEDs on at any time...uses MUCH less juice than
7+
// rainbow display!
8+
9+
#include <Adafruit_NeoPixel.h>
10+
11+
#define PIN 0
12+
#define NUM_LEDS 16
13+
14+
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN);
15+
16+
uint8_t mode = 0, // Current animation effect
17+
offset = 0; // Position of spinner animation
18+
uint32_t color = 0xFF8000; // Starting color = amber
19+
uint32_t prevTime; // Time of last animation mode switch
20+
21+
void setup() {
22+
pixels.begin();
23+
pixels.setBrightness(60); // ~1/3 brightness
24+
prevTime = millis(); // Starting time
25+
}
26+
27+
void loop() {
28+
uint8_t i;
29+
uint32_t t;
30+
31+
switch(mode) {
32+
33+
case 0: // Random sparkles - just one LED on at a time!
34+
i = random(NUM_LEDS); // Choose a random pixel
35+
pixels.setPixelColor(i, color); // Set it to current color
36+
pixels.show(); // Refresh LED states
37+
// Set same pixel to "off" color now but DON'T refresh...
38+
// it stays on for now...both this and the next random
39+
// pixel will be refreshed on the next pass.
40+
pixels.setPixelColor(i, 0);
41+
delay(10); // 10 millisecond delay
42+
break;
43+
44+
case 1: // Spinny wheel (4 LEDs on at a time)
45+
for(i=0; i<NUM_LEDS; i++) { // For each LED...
46+
uint32_t c = 0; // Assume pixel will be "off" color
47+
if(((offset + i) & 7) < 2) { // For each 8 pixels, 2 will be...
48+
c = color; // ...assigned the current color
49+
}
50+
pixels.setPixelColor(i, c); // Set color of pixel 'i'
51+
}
52+
pixels.show(); // Refresh LED states
53+
delay(50); // 50 millisecond delay
54+
offset++; // Shift animation by 1 pixel on next frame
55+
break;
56+
57+
// More animation modes could be added here!
58+
}
59+
60+
t = millis(); // Current time in milliseconds
61+
if((t - prevTime) > 8000) { // Every 8 seconds...
62+
mode++; // Advance to next animation mode
63+
if(mode > 1) { // End of modes?
64+
mode = 0; // Start over from beginning
65+
color >>= 8; // And change color
66+
if(!color) color = 0xFF8000; // preiodically reset to amber
67+
}
68+
pixels.clear(); // Set all pixels to 'off' state
69+
prevTime = t; // Record the time of the last mode change
70+
}
71+
}

Gemma/Gemma_Hoop_Earrings/code.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# SPDX-FileCopyrightText: 2017 Phillip Burgess for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
# NeoPixel earrings example. Makes a nice blinky display with just a
6+
# few LEDs on at any time...uses MUCH less juice than rainbow display!
7+
8+
import time
9+
from rainbowio import colorwheel
10+
import board
11+
import neopixel
12+
import adafruit_dotstar
13+
14+
try:
15+
import urandom as random # for v1.0 API support
16+
except ImportError:
17+
import random
18+
19+
dot = adafruit_dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)
20+
dot[0] = (0, 0, 0)
21+
22+
numpix = 16 # Number of NeoPixels (e.g. 16-pixel ring)
23+
pixpin = board.D0 # Pin where NeoPixels are connected
24+
strip = neopixel.NeoPixel(pixpin, numpix, brightness=.3, auto_write=False)
25+
26+
mode = 0 # Current animation effect
27+
offset = 0 # Position of spinner animation
28+
hue = 0 # Starting hue
29+
color = colorwheel(hue & 255) # hue -> RGB color
30+
prevtime = time.monotonic() # Time of last animation mode switch
31+
32+
while True: # Loop forever...
33+
if mode == 0: # Random sparkles - lights just one LED at a time
34+
i = random.randint(0, numpix - 1) # Choose random pixel
35+
strip[i] = color # Set it to current color
36+
strip.show() # Refresh LED states
37+
# Set same pixel to "off" color now but DON'T refresh...
38+
# it stays on for now...bot this and the next random
39+
# pixel will be refreshed on the next pass.
40+
strip[i] = [0, 0, 0]
41+
time.sleep(0.008) # 8 millisecond delay
42+
elif mode == 1: # Spinny colorwheel (4 LEDs on at a time)
43+
for i in range(numpix): # For each LED...
44+
if ((offset + i) & 7) < 2: # 2 pixels out of 8...
45+
strip[i] = color # are set to current color
46+
else:
47+
strip[i] = [0, 0, 0] # other pixels are off
48+
strip.show() # Refresh LED states
49+
time.sleep(0.04) # 40 millisecond delay
50+
offset += 1 # Shift animation by 1 pixel on next frame
51+
if offset >= 8:
52+
offset = 0
53+
# Additional animation modes could be added here!
54+
55+
t = time.monotonic() # Current time in seconds
56+
if (t - prevtime) >= 8: # Every 8 seconds...
57+
mode += 1 # Advance to next mode
58+
if mode > 1: # End of modes?
59+
mode = 0 # Start over from beginning
60+
hue += 80 # And change color
61+
color = colorwheel(hue & 255)
62+
strip.fill([0, 0, 0]) # Turn off all pixels
63+
prevtime = t # Record time of last mode change

0 commit comments

Comments
 (0)