Skip to content

Commit a364295

Browse files
committed
adding examples for the neorgb stemma breakout
adding arduino and CP examples for the neorgb stemma breakout. CP example checks for raspberry pi
1 parent e385697 commit a364295

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-FileCopyrightText: 2024 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <Adafruit_NeoPixel.h>
6+
#ifdef __AVR__
7+
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
8+
#endif
9+
10+
// Which pin on the Arduino is connected to the NeoPixels?
11+
// On a Trinket or Gemma we suggest changing this to 1:
12+
#define LED_PIN 6
13+
14+
// How many NeoPixels are attached to the Arduino?
15+
#define LED_COUNT 1
16+
17+
// Declare our NeoPixel strip object:
18+
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
19+
// Argument 1 = Number of pixels in NeoPixel strip
20+
// Argument 2 = Arduino pin number (most are valid)
21+
// Argument 3 = Pixel type flags
22+
23+
void setup() {
24+
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
25+
// Any other board, you can remove this part (but no harm leaving it):
26+
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
27+
clock_prescale_set(clock_div_1);
28+
#endif
29+
// END of Trinket-specific code.
30+
31+
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
32+
strip.show(); // Turn OFF all pixels ASAP
33+
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
34+
}
35+
void loop() {
36+
37+
rainbow(10); // Flowing rainbow cycle along the whole strip
38+
}
39+
40+
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
41+
void rainbow(int wait) {
42+
// Hue of first pixel runs 5 complete loops through the color wheel.
43+
// Color wheel has a range of 65536 but it's OK if we roll over, so
44+
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
45+
// means we'll make 5*65536/256 = 1280 passes through this loop:
46+
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
47+
// strip.rainbow() can take a single argument (first pixel hue) or
48+
// optionally a few extras: number of rainbow repetitions (default 1),
49+
// saturation and value (brightness) (both 0-255, similar to the
50+
// ColorHSV() function, default 255), and a true/false flag for whether
51+
// to apply gamma correction to provide 'truer' colors (default true).
52+
strip.rainbow(firstPixelHue);
53+
// Above line is equivalent to:
54+
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
55+
strip.show(); // Update strip with new contents
56+
delay(wait); // Pause for a moment
57+
}
58+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
from rainbowio import colorwheel
8+
import neopixel
9+
10+
num_pixels = 1
11+
# pylint: disable=simplifiable-condition
12+
# check to see if its a raspberry pi
13+
if "CE0" and "CE1" in dir(board): # pi only zone
14+
pixel_pin = board.D18
15+
# otherwise assume a microcontroller
16+
else:
17+
pixel_pin = board.D5
18+
19+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels)
20+
21+
color_offset = 0
22+
23+
while True:
24+
for i in range(num_pixels):
25+
rc_index = (i * 256 // num_pixels) + color_offset
26+
pixels[i] = colorwheel(rc_index & 255)
27+
pixels.show()
28+
color_offset += 1
29+
time.sleep(0.01)

0 commit comments

Comments
 (0)