ported to CircuitPython

This commit is contained in:
Mikey Sklar 2017-12-07 17:37:07 -07:00
parent 9cff521638
commit 4ff22ad5f1
3 changed files with 147 additions and 0 deletions

View file

@ -0,0 +1,65 @@
// Low power NeoPixel goggles example. Makes a nice blinky display
// with just a few LEDs on at any time.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
#include <avr/power.h>
#endif
#define PIN 0
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIN);
uint8_t mode = 0, // Current animation effect
offset = 0; // Position of spinny eyes
uint32_t color = 0xFF0000; // Start red
uint32_t prevTime;
void setup() {
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
if(F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
pixels.begin();
pixels.setBrightness(85); // 1/3 brightness
prevTime = millis();
}
void loop() {
uint8_t i;
uint32_t t;
switch(mode) {
case 0: // Random sparks - just one LED on at a time!
i = random(32);
pixels.setPixelColor(i, color);
pixels.show();
delay(10);
pixels.setPixelColor(i, 0);
break;
case 1: // Spinny wheels (8 LEDs on at a time)
for(i=0; i<16; i++) {
uint32_t c = 0;
if(((offset + i) & 7) < 2) c = color; // 4 pixels on...
pixels.setPixelColor( i, c); // First eye
pixels.setPixelColor(31-i, c); // Second eye (flipped)
}
pixels.show();
offset++;
delay(50);
break;
}
t = millis();
if((t - prevTime) > 8000) { // Every 8 seconds...
mode++; // Next mode
if(mode > 1) { // End of modes?
mode = 0; // Start modes over
color >>= 8; // Next color R->G->B
if(!color) color = 0xFF0000; // Reset to red
}
for(i=0; i<32; i++) pixels.setPixelColor(i, 0);
prevTime = t;
}
}

View file

@ -0,0 +1,77 @@
#
# Kaleidoscope_Eyes_NeoPixel_LED_Goggles.py
#
import board
import neopixel
import time
try:
import urandom as random # for v1.0 API support
except ImportError:
import random
numpix = 32 # Number of NeoPixels
pixpin = board.D0 # Pin where NeoPixels are connected
mode = 0 # Current animation effect
offset = 0 # Position of spinny eyes
rgb_colors = ( [255,0,0], # red
[0,255,0], # green
[0,0,255] ) # blue
rgb_idx = 0 # index counter - primary color we are on
color = rgb_colors[rgb_idx]
prevtime = 0
pixels = neopixel.NeoPixel(pixpin, numpix, brightness=.3, auto_write=False)
def setup():
prevtime = time.monotonic()
setup()
while True:
i = 0
t = 0
# Random sparks - just one LED on at a time!
if ( mode == 0 ):
i = random.randint(0, (numpix - 1))
pixels[i] = color
pixels.write()
time.sleep(0.01)
pixels[i] = (0,0,0)
# Spinny wheels (8 LEDs on at a time)
elif ( mode == 1 ):
for i in range(0, numpix):
c = 0
# 4 pixels on...
if (((offset + i) & 7) < 2):
c = color
pixels[i] = c # First eye
pixels[(numpix - 1) - i] = c # Second eye (flipped)
pixels.write()
offset += 1
time.sleep(0.05);
t = time.monotonic()
if ((t - prevtime) > 8): # Every 8 seconds...
mode += 1 # Next mode
if( mode > 1 ): # End of modes?
mode = 0 # Start modes over
if ( rgb_idx > 2 ): # reset R-->G-->B rotation
rgb_idx = 0
color = rgb_colors[rgb_idx] # next color assignment
rgb_idx += 1
for i in range(0, numpix):
pixels[i] = (0,0,0)
prevtime = t

View file

@ -0,0 +1,5 @@
# Kaleidoscope_Eyes_NeoPixel_LED_Goggles
Code to accompany this tutorial:
https://learn.adafruit.com/kaleidoscope-eyes-neopixel-led-goggles-trinket-gemma