Skip to content

Commit 1f29ffe

Browse files
authored
Add files via upload
1 parent 707a988 commit 1f29ffe

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// SPDX-FileCopyrightText: 2017 Mikey Sklar for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Adafruit_NeoPixel.h>
6+
#define PIN 1
7+
#define NUM_LEDS 3
8+
9+
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
10+
11+
// R G B
12+
uint8_t myColors[][5] = {
13+
{30, 144, 255}, // dodger blue
14+
{232, 100, 255}, // purple
15+
{204, 0, 204}, //
16+
{200, 200, 20}, // yellow
17+
{30, 200, 200}, // blue
18+
};
19+
20+
// don't edit the line below
21+
#define FAVCOLORS sizeof(myColors) / 5
22+
23+
void setup() {
24+
strip.begin();
25+
strip.setBrightness(20);
26+
strip.show(); // Initialize all pixels to 'off'
27+
}
28+
29+
void loop() {
30+
flashRandom(10, 1); // first number is 'wait' delay, shorter num == shorter twinkle
31+
flashRandom(10, 3); // second number is how many neopixels to simultaneously light up
32+
flashRandom(10, 2);
33+
}
34+
35+
void flashRandom(int wait, uint8_t howmany) {
36+
37+
for(uint16_t i=0; i<howmany; i++) {
38+
// pick a random favorite color!
39+
int c = random(FAVCOLORS);
40+
int red = myColors[c][0];
41+
int green = myColors[c][1];
42+
int blue = myColors[c][2];
43+
44+
// get a random pixel from the list
45+
int j = random(strip.numPixels());
46+
47+
// now we will 'fade' it in 5 steps
48+
for (int x=0; x < 5; x++) {
49+
int r = red * (x+1); r /= 5;
50+
int g = green * (x+1); g /= 5;
51+
int b = blue * (x+1); b /= 5;
52+
53+
strip.setPixelColor(j, strip.Color(r, g, b));
54+
strip.show();
55+
delay(wait);
56+
}
57+
// & fade out in 5 steps
58+
for (int x=5; x >= 0; x--) {
59+
int r = red * x; r /= 5;
60+
int g = green * x; g /= 5;
61+
int b = blue * x; b /= 5;
62+
63+
strip.setPixelColor(j, strip.Color(r, g, b));
64+
strip.show();
65+
delay(wait);
66+
}
67+
}
68+
// LEDs will be off when done (they are faded to 0)
69+
}

Gemma/Gemma_Nano_Ring/code.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# SPDX-FileCopyrightText: 2017 Mikey Sklar 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
12+
except ImportError:
13+
import random
14+
15+
numpix = 3 # Number of NeoPixels
16+
pixpin = board.D1 # Pin where NeoPixels are connected
17+
strip = neopixel.NeoPixel(pixpin, numpix, brightness=.1, auto_write=True)
18+
colors = [
19+
[30, 144, 255], # Dodger Blue
20+
[232, 100, 255], # Purple
21+
[204, 0, 204], # Pink
22+
[200, 200, 20], # Yellow
23+
[30, 200, 200], # Blue
24+
]
25+
26+
27+
def flash_random(wait, howmany):
28+
for _ in range(howmany):
29+
30+
c = random.randint(0, len(colors) - 1) # Choose random color index
31+
j = random.randint(0, numpix - 1) # Choose random pixel
32+
strip[j] = colors[c] # Set pixel to color
33+
34+
for i in range(1, 5):
35+
strip.brightness = i / 5.0 # Ramp up brightness
36+
time.sleep(wait)
37+
38+
for i in range(5, 0, -1):
39+
strip.brightness = i / 5.0 # Ramp down brightness
40+
time.sleep(wait)
41+
strip[j] = [0, 0, 0] # Set pixel to 'off'
42+
43+
while True:
44+
# first number is 'wait' delay, shorter num == shorter twinkle
45+
flash_random(.01, 1)
46+
# second number is how many neopixels to simultaneously light up
47+
flash_random(.01, 3)
48+
flash_random(.01, 2)

0 commit comments

Comments
 (0)