Skip to content

Commit 0b89bcc

Browse files
authored
Add files via upload
1 parent 4d16417 commit 0b89bcc

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// SPDX-FileCopyrightText: 2017 Phillip Burgess for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Adafruit_NeoPixel.h>
6+
7+
#define PIN 1
8+
#define NUM_LEDS 36
9+
10+
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN);
11+
12+
uint8_t mode = 0, // Current animation effect
13+
offset = 0; // Position of spinner animation
14+
uint32_t color = 0xA000A0; // Purple
15+
uint32_t prevTime; // Time of last animation mode switch
16+
17+
void setup() {
18+
pixels.begin();
19+
pixels.setBrightness(255); // Full brightness
20+
prevTime = millis(); // Starting time
21+
}
22+
23+
void loop() {
24+
uint8_t i;
25+
uint32_t t;
26+
27+
switch(mode) {
28+
29+
case 0: // Random sparkles - just one LED on at a time!
30+
i = random(NUM_LEDS); // Choose a random pixel
31+
pixels.setPixelColor(i, color); // Set it to current color
32+
pixels.show(); // Refresh LED states
33+
// Set same pixel to "off" color now but DON'T refresh...
34+
// it stays on for now...both this and the next random
35+
// pixel will be refreshed on the next pass.
36+
pixels.setPixelColor(i, 0);
37+
delay(10); // 10 millisecond delay
38+
break;
39+
40+
case 1: // Spinny wheel
41+
for(i=0; i<NUM_LEDS; i++) { // For each LED...
42+
uint32_t c = 0; // Assume pixel will be "off" color
43+
if(((offset + i) & 7) < 2) { // For each 8 pixels, 2 will be...
44+
c = color; // ...assigned the current color
45+
}
46+
pixels.setPixelColor(i, c); // Set color of pixel 'i'
47+
}
48+
pixels.show(); // Refresh LED states
49+
delay(90); // 90 millisecond delay
50+
offset++; // Shift animation by 1 pixel on next frame
51+
break;
52+
53+
// More animation modes could be added here!
54+
}
55+
56+
t = millis(); // Current time in milliseconds
57+
if((t - prevTime) > 8000) { // Every 8 seconds...
58+
mode++; // Advance to next animation mode
59+
if(mode > 1) { // End of modes?
60+
mode = 0; // Start over from beginning
61+
}
62+
pixels.clear(); // Set all pixels to 'off' state
63+
prevTime = t; // Record the time of the last mode change
64+
}
65+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# SPDX-FileCopyrightText: 2017 Phillip Burgess for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
7+
import board
8+
import neopixel
9+
10+
try:
11+
import urandom as random # for v1.0 API support
12+
except ImportError:
13+
import random
14+
15+
numpix = 36 # Number of NeoPixels
16+
pixpin = board.D1 # Pin where NeoPixels are connected
17+
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1.0)
18+
19+
mode = 0 # Current animation effect
20+
offset = 0 # Position of spinner animation
21+
color = [160, 0, 160] # RGB color - purple
22+
prevtime = time.monotonic() # Time of last animation mode switch
23+
24+
while True: # Loop forever...
25+
26+
if mode == 0: # Random sparkles - lights just one LED at a time
27+
i = random.randint(0, numpix - 1) # Choose random pixel
28+
strip[i] = color # Set it to current color
29+
strip.write() # Refresh LED states
30+
# Set same pixel to "off" color now but DON'T refresh...
31+
# it stays on for now...bot this and the next random
32+
# pixel will be refreshed on the next pass.
33+
strip[i] = [0, 0, 0]
34+
time.sleep(0.008) # 8 millisecond delay
35+
elif mode == 1: # Spinny wheel (4 LEDs on at a time)
36+
for i in range(numpix): # For each LED...
37+
if ((offset + i) & 7) < 2: # 2 pixels out of 8...
38+
strip[i] = color # are set to current color
39+
else:
40+
strip[i] = [0, 0, 0] # other pixels are off
41+
strip.write() # Refresh LED states
42+
time.sleep(0.08) # 80 millisecond delay
43+
offset += 1 # Shift animation by 1 pixel on next frame
44+
if offset >= 8:
45+
offset = 0
46+
# Additional animation modes could be added here!
47+
48+
t = time.monotonic() # Current time in seconds
49+
if (t - prevtime) >= 8: # Every 8 seconds...
50+
mode += 1 # Advance to next mode
51+
if mode > 1: # End of modes?
52+
mode = 0 # Start over from beginning
53+
strip.fill([0, 0, 0]) # Turn off all pixels
54+
prevtime = t # Record time of last mode change

0 commit comments

Comments
 (0)