Merge remote-tracking branch 'adafruit/master'

This commit is contained in:
Phillip Burgess 2017-12-27 15:16:29 -08:00
commit c258e5bac6
14 changed files with 1424 additions and 32 deletions

Binary file not shown.

View file

@ -0,0 +1,128 @@
/*
Close Encounters hat with 10 neopixels by Leslie Birch for Adafruit Industries.
Notes play with each corresponding light.
Based on code by Becky Stern, Mike Barela and T Main for Adafruit Industries
http://learn.adafruit.com/adafruit-trinket-modded-stuffed-animal/animal-sounds
*/
const int speaker = 0; // the number of the speaker
#define PHOTOCELL 1 // cDS photocell on A1
// this section is Close Encounters Sounds
#define toneC 1046.50
#define toneG 1567.98
#define tonec 2093.00
#define toned 2349.32
#define tonee 2637.02
#define tonep 0
#define darkness_min 512 // analog 0-1024 0-512 (light, 513-1023 dark)
long vel = 20000;
// This section is NeoPixel Variables
#include <Adafruit_NeoPixel.h>
#define PIN 1
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, 1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, 1);
void setup() {
pinMode(speaker, OUTPUT);
Serial.println("setup");
//This is for Neopixel Setup
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop()
{
// turn lights and audio on when dark
// less than 50% light on analog pin
if ( analogRead(PHOTOCELL) > darkness_min ) {
alien(); // Close Encounters Loop
}
}
// the sound producing function
void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds)
{ // http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html
int x;
long delayAmount = (long)(1000000/frequencyInHertz);
long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2));
for (x=0;x<loopTime;x++)
{
digitalWrite(speakerPin,HIGH);
delayMicroseconds(delayAmount);
digitalWrite(speakerPin,LOW);
delayMicroseconds(delayAmount);
}
}
// Generate the Close Encounters LEDs
void alien() {
strip.setBrightness(64);
strip.setPixelColor(8, 255, 255, 0); //yellow front
strip.setPixelColor(3, 255, 255, 0); //yellow back
strip.show();
beep(speaker,toned,1000);
delay(25);
strip.setPixelColor(8, 0, 0, 0); //clear front
strip.setPixelColor(3, 0, 0, 0); //clear back
strip.show();
delay(25);
strip.setPixelColor(7, 255, 0, 255); //pink front
strip.setPixelColor(2, 255, 0, 255); //pink back
strip.show();
beep(speaker,tonee,1000);
delay(25);
strip.setPixelColor(7, 0, 0, 0); //clear front
strip.setPixelColor(2, 0, 0, 0); //clear back
strip.show();
delay(25);
strip.setPixelColor(4, 128, 255, 0); //green front
strip.setPixelColor(9, 128, 255, 0); //green back
strip.show();
beep(speaker,tonec,1000);
delay(25);
strip.setPixelColor(4, 0, 0, 0); //clear front
strip.setPixelColor(9, 0, 0, 0); //clear back
strip.show();
delay(25);
strip.setPixelColor(5, 0, 0, 255); //blue front
strip.setPixelColor(0, 0, 0, 255); //blue back
strip.show();
beep(speaker,toneC,1000);
delay(75);
strip.setPixelColor(5, 0, 0, 0); //clear front
strip.setPixelColor(0, 0, 0, 0); //clear back
strip.show();
delay(100);
strip.setPixelColor(6, 255, 0, 0); //red front
strip.setPixelColor(1, 255, 0, 0); //red back
strip.show();
beep(speaker,toneG,1000);
delay(100);
strip.setPixelColor(6, 0, 0, 0); //clear front
strip.setPixelColor(1, 0, 0, 0); //clear back
strip.show();
delay(100);
}

View file

@ -0,0 +1,91 @@
# Close Encounters Hat with 10 NeoPixels
# ported from Leslie Birch's Arduino to CircuitPython
#
# Photocell voltage divider center wire to GPIO #2 (analog 1)
# and output tone to GPIO #0 (digital 0)
import board
import analogio
import time
import neopixel
import simpleio
# Initialize input/output pins
photocell_pin = board.A1 # cds photocell connected to this ANALOG pin
speaker_pin = board.D0 # speaker is connected to this DIGITAL pin
pixpin = board.D1 # pin where NeoPixels are connected
numpix = 10 # number of neopixels`
darkness_min = (2**16 / 2) # more dark than light > 32k out of 64k
photocell = analogio.AnalogIn(photocell_pin)
strip = neopixel.NeoPixel(pixpin, numpix, brightness=.4)
# this section is Close Encounters Sounds
toned = 294
tonee = 330
tonec = 262
toneC = 130
toneg = 392
def alien():
strip[8] = (255, 255, 0) # yellow front
strip[3] = (255, 255, 0) # yellow back
simpleio.tone(speaker_pin, toned, 1) # play tone for 1 second
time.sleep(.025)
strip[8] = (0, 0, 0) # clear front
strip[3] = (0, 0, 0) # clear back
time.sleep(.025)
strip[7] = (255, 0, 255) # pink front
strip[2] = (255, 0, 255) # pink back
simpleio.tone(speaker_pin, tonee, 1) # play tone for 1 second
time.sleep(.025)
strip[7] = (0, 0, 0) # clear front
strip[2] = (0, 0, 0) # clear back
time.sleep(.025)
strip[4] = (128, 255, 0) # green front
strip[9] = (128, 255, 0) # green back
simpleio.tone(speaker_pin, tonec, 1) # play tone for 1 second
time.sleep(.025)
strip[4] = (0, 0, 0) # clear front
strip[9] = (0, 0, 0) # clear back
time.sleep(.025)
strip[5] = (0, 0, 255) # blue front
strip[0] = (0, 0, 255) # blue back
simpleio.tone(speaker_pin, toneC, 1) # play tone for 1 second
time.sleep(.075)
strip[5] = (0, 0, 0) # clear front
strip[0] = (0, 0, 0) # clear back
time.sleep(.1)
strip[6] = (255, 0, 0) # red front
strip[1] = (255, 0, 0) # red back
simpleio.tone(speaker_pin, toneg, 1) # play tone for 1 second
time.sleep(.1)
strip[6] = (0, 0, 0) # clear front
strip[1] = (0, 0, 0) # clear back
time.sleep(.1)
# Loop forever...
while True:
# turn lights and audio on when dark
# (less than 50% light on analog pin)
if ( photocell.value > darkness_min ):
alien() # close Encounters Loop

Binary file not shown.

View file

@ -74,8 +74,8 @@ while True:
if cpx.button_a: # this means the button has been pressed
# grab the current_dial_position value and add to the list
entered_combo.append(current_dial_position)
dialMsg = 'Dial Position: ' + str(entered_combo[(len(entered_combo)-1)])
print(dialMsg)
dial_msg = 'Dial Position: ' + str(entered_combo[(len(entered_combo)-1)])
print(dial_msg)
cpx.play_tone(320, 0.3) # beep
time.sleep(1) # slow down button checks

View file

@ -0,0 +1,4 @@
# Flora Sparkle Skirt
Code to accompany this tutorial:
https://learn.adafruit.com/sparkle-skirt/

View file

@ -0,0 +1,116 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_NeoPixel.h>
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, 6, NEO_GRB + NEO_KHZ800);
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);
// Here is where you can put in your favorite colors that will appear!
// just add new {nnn, nnn, nnn}, lines. They will be picked out randomly
// R G B
uint8_t myFavoriteColors[][3] = {{200, 0, 200}, // purple
{200, 0, 0}, // red
{200, 200, 200}, // white
};
// don't edit the line below
#define FAVCOLORS sizeof(myFavoriteColors) / 3
// mess with this number to adjust TWINklitude :)
// lower number = more sensitive
#define MOVE_THRESHOLD 45
void setup()
{
Serial.begin(9600);
// Try to initialise and warn if we couldn't detect the chip
if (!accel.begin())
{
Serial.println("Oops ... unable to initialize the LSM303. Check your wiring!");
while (1);
}
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop()
{
/* Get a new sensor event */
sensors_event_t event;
accel.getEvent(&event);
Serial.print("Accel X: "); Serial.print(event.acceleration.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");
// Get the magnitude (length) of the 3 axis vector
// http://en.wikipedia.org/wiki/Euclidean_vector#Length
double storedVector = event.acceleration.x*event.acceleration.x;
storedVector += event.acceleration.y*event.acceleration.y;
storedVector += event.acceleration.z*event.acceleration.z;
storedVector = sqrt(storedVector);
Serial.print("Len: "); Serial.println(storedVector);
// wait a bit
delay(100);
// get new data!
accel.getEvent(&event);
double newVector = event.acceleration.x*event.acceleration.x;
newVector += event.acceleration.y*event.acceleration.y;
newVector += event.acceleration.z*event.acceleration.z;
newVector = sqrt(newVector);
Serial.print("New Len: "); Serial.println(newVector);
// are we moving
if (abs(newVector - storedVector) > MOVE_THRESHOLD) {
Serial.println("Twinkle!");
flashRandom(5, 1); // first number is 'wait' delay, shorter num == shorter twinkle
flashRandom(5, 3); // second number is how many neopixels to simultaneously light up
flashRandom(5, 2);
}
}
void flashRandom(int wait, uint8_t howmany) {
for(uint16_t i=0; i<howmany; i++) {
// pick a random favorite color!
int c = random(FAVCOLORS);
int red = myFavoriteColors[c][0];
int green = myFavoriteColors[c][1];
int blue = myFavoriteColors[c][2];
// get a random pixel from the list
int j = random(strip.numPixels());
//Serial.print("Lighting up "); Serial.println(j);
// now we will 'fade' it in 5 steps
for (int x=0; x < 5; x++) {
int r = red * (x+1); r /= 5;
int g = green * (x+1); g /= 5;
int b = blue * (x+1); b /= 5;
strip.setPixelColor(j, strip.Color(r, g, b));
strip.show();
delay(wait);
}
// & fade out in 5 steps
for (int x=5; x >= 0; x--) {
int r = red * x; r /= 5;
int g = green * x; g /= 5;
int b = blue * x; b /= 5;
strip.setPixelColor(j, strip.Color(r, g, b));
strip.show();
delay(wait);
}
}
// LEDs will be off when done (they are faded to 0)
}

Binary file not shown.

View file

@ -0,0 +1,106 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Dan Halbert for Adafruit Industries
# Copyright (c) 2017 Kattni Rembor, Tony DiCola for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import array
import audiobusio
import board
import math
import neopixel
# Exponential scaling factor.
# Should probably be in range -10 .. 10 to be reasonable.
CURVE = 2
SCALE_EXPONENT = math.pow(10, CURVE*-0.1)
PEAK_COLOR = (100, 0, 255)
NUM_PIXELS = 10
# Number of samples to read at once.
NUM_SAMPLES = 160
# Restrict value to be between floor and ceiling.
def constrain(value, floor, ceiling):
return max(floor, min(value, ceiling))
# Scale input_value to be between output_min and output_max, in an exponential way.
def log_scale(input_value, input_min, input_max, output_min, output_max):
normalized_input_value = (input_value - input_min) / (input_max - input_min)
return output_min + math.pow(normalized_input_value, SCALE_EXPONENT) * (output_max - output_min)
# Remove DC bias before computing RMS.
def normalized_rms(values):
minbuf = int(mean(values))
return math.sqrt(sum(float((sample-minbuf)*(sample-minbuf)) for sample in values)/len(values))
def mean(values):
return (sum(values) / len(values))
def volume_color(i):
return (200, i*(255//NUM_PIXELS), 0)
# Main program
# Set up NeoPixels and turn them all off.
pixels = neopixel.NeoPixel(board.NEOPIXEL, NUM_PIXELS, brightness=0.1, auto_write=False)
pixels.fill(0)
pixels.show()
mic = audiobusio.PDMIn(board.MICROPHONE_CLOCK, board.MICROPHONE_DATA, frequency=16000, bit_depth=16)
# Record an initial sample to calibrate. Assume it's quiet when we start.
samples = array.array('H', [0] * NUM_SAMPLES)
mic.record(samples, len(samples))
# Set lowest level to expect, plus a little.
input_floor = normalized_rms(samples) + 10
# OR: used a fixed floor
# input_floor = 50
# You might want to print the input_floor to help adjust other values.
# print(input_floor)
# Corresponds to sensitivity: lower means more pixels light up with lower sound
# Adjust this as you see fit.
input_ceiling = input_floor + 500
peak = 0
while True:
mic.record(samples, len(samples))
magnitude = normalized_rms(samples)
# You might want to print this to see the values.
# print(magnitude)
# Compute scaled logarithmic reading in the range 0 to NUM_PIXELS
c = log_scale(constrain(magnitude, input_floor, input_ceiling), input_floor, input_ceiling, 0, NUM_PIXELS)
# Light up pixels that are below the scaled and interpolated magnitude.
pixels.fill(0)
for i in range(NUM_PIXELS):
if i < c:
pixels[i] = volume_color(i)
# Light up the peak pixel and animate it slowly dropping.
if c >= peak:
peak = min(c, NUM_PIXELS-1)
elif peak > 0:
peak = peak - 1
if peak > 0:
pixels[int(peak)] = PEAK_COLOR
pixels.show()

View file

@ -1,30 +0,0 @@
# The MIT License (MIT)
#
# Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
"""
`adafruit_hid`
====================================================
This driver simulates USB HID devices. Currently keyboard and mouse are implemented.
* Author(s): Scott Shawcroft, Dan Halbert
"""

View file

@ -0,0 +1,86 @@
# Circuit Playground Express CircuitPython Morse Code Flasher
# This is meant to work with the Circuit Playground Express board:
# https://www.adafruit.com/product/3333
# Needs the NeoPixel module installed:
# https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel
# Author: Collin Cunningham
# License: MIT License (https://opensource.org/licenses/MIT)
import time
import board
import neopixel
# Configuration:
message = 'SOS' # Message to display (capital letters and numbers only)
dot_length = 0.15 # Duration of one Morse dot
dash_length = (dot_length * 3.0) # Duration of one Morse dash
symbol_gap = dot_length # Duration of gap between dot or dash
character_gap = (dot_length * 3.0) # Duration of gap between characters
flash_color = (255, 0, 0) # Color of the morse display.
brightness = 0.5 # Display brightness (0.0 - 1.0)
morse = [('A', '.-'), ('B', '-...'), ('C', '-.-.'), ('D', '-..'), ('E', '.'), ('F', '..-.'), ('G', '--.'), ('H', '....'), ('I', '..'), ('J', '.---'), ('K', '-.-'), ('L', '.-..'), ('M', '--'), ('N', '-.'), ('O', '---'), ('P', '.--.'), ('Q', '--.-'), ('R', '.-.'), ('S', '...'), ('T', '-'), ('U', '..-'), ('V', '...-'), ('W', '.--'), ('X', '-..-'), ('Y', '-.--'), ('Z', '--..'), ('0', '-----'), ('1', '.----'), ('2', '..---'), ('3', '...--'), ('4', '....-'), ('5', '.....'), ('6', '-....'), ('7', '--...'), ('8', '---..'), ('9', '----.')]
# Define a class that represents the morse flasher.
class MorseFlasher:
def __init__(self, color=(255,255,255)):
#set the color adjusted for brightness
self._color = (int(color[0]*brightness), int(color[1]*brightness), int(color[2]*brightness))
def light(self, on=True):
if on:
pixels.fill(self._color)
else:
pixels.fill((0,0,0))
pixels.show()
def showDot(self):
self.light(True)
time.sleep(dot_length)
self.light(False)
time.sleep(symbol_gap)
def showDash(self):
self.light(True)
time.sleep(dash_length)
self.light(False)
time.sleep(symbol_gap)
def encode(self, str):
output = ""
#iterate through string's characters
for c in str:
#find morse code for a character
for x in morse:
if x[0] == c:
#add code to output
output += x[1]
# add a space in between characters
output += " "
#save complete morse code output to display
self.display(output)
def display(self, code=".-.-.- "):
# iterate through morse code symbols
for c in code:
# show a dot
if c == ".":
self.showDot()
# show a dash
elif c == "-":
self.showDash()
# show a gap
elif c == " ":
time.sleep(character_gap)
# Initialize NeoPixels
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False)
pixels.fill((0, 0, 0))
pixels.show()
# Create a morse flasher object.
flasher = MorseFlasher(flash_color)
# Main loop will run forever
while True:
flasher.encode(message)

View file

@ -0,0 +1,104 @@
// On Leonardo/Micro or others with hardware serial, use those!
// uncomment this line:
// #define pmsSerial Serial1
// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (TX pin on sensor), leave pin #3 disconnected
// comment these two lines if using hardware serial
#include <SoftwareSerial.h>
SoftwareSerial pmsSerial(2, 3);
void setup() {
// our debugging output
Serial.begin(115200);
// sensor baud rate is 9600
pmsSerial.begin(9600);
}
struct pms5003data {
uint16_t framelen;
uint16_t pm10_standard, pm25_standard, pm100_standard;
uint16_t pm10_env, pm25_env, pm100_env;
uint16_t particles_03um, particles_05um, particles_10um, particles_25um, particles_50um, particles_100um;
uint16_t unused;
uint16_t checksum;
};
struct pms5003data data;
void loop() {
if (readPMSdata(&pmsSerial)) {
// reading data was successful!
Serial.println();
Serial.println("---------------------------------------");
Serial.println("Concentration Units (standard)");
Serial.println("---------------------------------------");
Serial.print("PM 1.0: "); Serial.print(data.pm10_standard);
Serial.print("\t\tPM 2.5: "); Serial.print(data.pm25_standard);
Serial.print("\t\tPM 10: "); Serial.println(data.pm100_standard);
Serial.println("Concentration Units (environmental)");
Serial.println("---------------------------------------");
Serial.print("PM 1.0: "); Serial.print(data.pm10_env);
Serial.print("\t\tPM 2.5: "); Serial.print(data.pm25_env);
Serial.print("\t\tPM 10: "); Serial.println(data.pm100_env);
Serial.println("---------------------------------------");
Serial.print("Particles > 0.3um / 0.1L air:"); Serial.println(data.particles_03um);
Serial.print("Particles > 0.5um / 0.1L air:"); Serial.println(data.particles_05um);
Serial.print("Particles > 1.0um / 0.1L air:"); Serial.println(data.particles_10um);
Serial.print("Particles > 2.5um / 0.1L air:"); Serial.println(data.particles_25um);
Serial.print("Particles > 5.0um / 0.1L air:"); Serial.println(data.particles_50um);
Serial.print("Particles > 50 um / 0.1L air:"); Serial.println(data.particles_100um);
Serial.println("---------------------------------------");
}
}
boolean readPMSdata(Stream *s) {
if (! s->available()) {
return false;
}
// Read a byte at a time until we get to the special '0x42' start-byte
if (s->peek() != 0x42) {
s->read();
return false;
}
// Now read all 32 bytes
if (s->available() < 32) {
return false;
}
uint8_t buffer[32];
uint16_t sum = 0;
s->readBytes(buffer, 32);
// get checksum ready
for (uint8_t i=0; i<30; i++) {
sum += buffer[i];
}
/* debugging
for (uint8_t i=2; i<32; i++) {
Serial.print("0x"); Serial.print(buffer[i], HEX); Serial.print(", ");
}
Serial.println();
*/
// The data comes in endian'd, this solves it so it works on all platforms
uint16_t buffer_u16[15];
for (uint8_t i=0; i<15; i++) {
buffer_u16[i] = buffer[2 + i*2 + 1];
buffer_u16[i] += (buffer[2 + i*2] << 8);
}
// put it into a nice struct :)
memcpy((void *)&data, (void *)buffer_u16, 30);
if (sum != data.checksum) {
Serial.println("Checksum failure");
return false;
}
// success!
return true;
}

View file

@ -0,0 +1,111 @@
import adafruit_irremote
import board
import digitalio
import neopixel
import pulseio
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10)
red_led = digitalio.DigitalInOut(board.D13)
red_led.direction = digitalio.Direction.OUTPUT
pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
decoder = adafruit_irremote.GenericDecode()
# among others, this example works with the Adafruit mini IR remote:
# https://www.adafruit.com/product/389
# size must match what you are decoding! for NEC use 4
received_code = bytearray(4)
# IR Remote Mapping
'''
1: [255, 2, 247, 8]
2: [255, 2, 119, 136]
3: [255, 2, 183, 72]
4: [255, 2, 215, 40]
5: [255, 2, 87, 168]
6: [255, 2, 151, 104]
7: [255, 2, 231, 24]
8: [255, 2, 103, 152]
9: [255, 2, 167, 88]
0: [255, 2, 207, 48]
^ : [255, 2, 95, 160]
v : [255, 2, 79, 176]
> : [255, 2, 175, 80]
< : [255, 2, 239, 16]
Enter: [255, 2, 111, 144]
Setup: [255, 2, 223, 32]
Stop/Mode: [255, 2, 159, 96]
Back: [255, 2, 143, 112]
Vol - : [255, 2, 255, 0]
Vol + : [255, 2, 191, 64]
Play/Pause: [255, 2, 127, 128]
'''
RED = (255, 0, 0)
GREEN = (0, 255, 0)
WHITE = (85, 85, 85)
BLUE = (0, 0, 255)
PINK = (128, 0, 128)
YELLOW = (148, 108, 0)
PURPLE = (200, 0, 55)
TEAL = (0, 200, 100)
ORANGE = (100, 45, 0)
BLACK = (0, 0, 0)
last_command = None
while True:
red_led.value = False
try:
pulses = decoder.read_pulses(pulsein)
except MemoryError as e:
print("Memory error: ", e)
continue
red_led.value = True
print("Heard", len(pulses), "Pulses:", pulses)
command = None
try:
code = decoder.decode_bits(pulses, debug=False)
if len(code) > 3:
command = code[2]
print("Decoded:", code)
except adafruit_irremote.IRNECRepeatException: # unusual short code!
print("NEC repeat!")
command = last_command
except adafruit_irremote.IRDecodeException as e: # failed to decode
print("Failed to decode:", e)
except MemoryError as e:
print("Memory error: ", e)
if not command:
continue
last_command = command
print("----------------------------")
red_led.value = False
if command == 247: # IR button 1
pixels.fill(RED)
elif command == 119: # 2
pixels.fill(GREEN)
elif command == 183: # 3
pixels.fill(WHITE)
elif command == 215: # 4
pixels.fill(BLUE)
elif command == 87: # 5
pixels.fill(PINK)
elif command == 151: # 6
pixels.fill(YELLOW)
elif command == 231: # 7
pixels.fill(PURPLE)
elif command == 103: # 8
pixels.fill(TEAL)
elif command == 167: # 9
pixels.fill(ORANGE)
elif command == 207:
pixels.fill(BLACK) # 0/10+

View file

@ -0,0 +1,676 @@
#include "FastLED.h"
// ColorWavesWithPalettes
// Animated shifting color waves, with several cross-fading color palettes.
// by Mark Kriegsman, August 2015
//
// Color palettes courtesy of cpt-city and its contributors:
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/
//
// Color palettes converted for FastLED using "PaletteKnife" v1:
// http://fastled.io/tools/paletteknife/
//
//#if FASTLED_VERSION < 3001000
//#error "Requires FastLED 3.1 or later; check github for latest code."
//#endif
#define DATA_PIN 6
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
#define NUM_LEDS 400 // Change this to reflect the number of LEDs you have
#define BRIGHTNESS 80 // Set Brightness here
CRGB leds[NUM_LEDS];
// ten seconds per color palette makes a good demo
// 20-120 is better for deployment
#define SECONDS_PER_PALETTE 20
void setup() {
delay(3000); // 3 second delay for recovery
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
.setCorrection(TypicalLEDStrip) // cpt-city palettes have different color balance
.setDither(BRIGHTNESS < 255);
// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}
// Forward declarations of an array of cpt-city gradient palettes, and
// a count of how many there are. The actual color palette definitions
// are at the bottom of this file.
extern const TProgmemRGBGradientPalettePtr gGradientPalettes[];
extern const uint8_t gGradientPaletteCount;
// Current palette number from the 'playlist' of color palettes
uint8_t gCurrentPaletteNumber = 0;
CRGBPalette16 gCurrentPalette( CRGB::Black);
CRGBPalette16 gTargetPalette( gGradientPalettes[0] );
// This function draws color waves with an ever-changing,
// widely-varying set of parameters, using a color palette.
void colorwaves( CRGB* ledarray, uint16_t numleds, CRGBPalette16& palette)
{
static uint16_t sPseudotime = 0;
static uint16_t sLastMillis = 0;
static uint16_t sHue16 = 0;
uint8_t sat8 = beatsin88( 87, 220, 250);
uint8_t brightdepth = beatsin88( 341, 96, 224);
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t hue16 = sHue16;//gHue * 256;
uint16_t hueinc16 = beatsin88(113, 300, 1500);
uint16_t ms = millis();
uint16_t deltams = ms - sLastMillis ;
sLastMillis = ms;
sPseudotime += deltams * msmultiplier;
sHue16 += deltams * beatsin88( 400, 5,9);
uint16_t brightnesstheta16 = sPseudotime;
for( uint16_t i = 0 ; i < numleds; i++) {
hue16 += hueinc16;
uint8_t hue8 = hue16 / 256;
uint16_t h16_128 = hue16 >> 7;
if( h16_128 & 0x100) {
hue8 = 255 - (h16_128 >> 1);
} else {
hue8 = h16_128 >> 1;
}
brightnesstheta16 += brightnessthetainc16;
uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth);
uint8_t index = hue8;
//index = triwave8( index);
index = scale8( index, 240);
CRGB newcolor = ColorFromPalette( palette, index, bri8);
uint16_t pixelnumber = i;
pixelnumber = (numleds-1) - pixelnumber;
nblend( ledarray[pixelnumber], newcolor, 128);
}
}
// Alternate rendering function just scrolls the current palette
// across the defined LED strip.
void palettetest( CRGB* ledarray, uint16_t numleds, const CRGBPalette16& gCurrentPalette)
{
static uint8_t startindex = 0;
startindex--;
fill_palette( ledarray, numleds, startindex, (256 / NUM_LEDS) + 1, gCurrentPalette, 255, LINEARBLEND);
}
// Gradient Color Palette definitions for 33 different cpt-city color palettes.
// 956 bytes of PROGMEM for all of the palettes together,
// +618 bytes of PROGMEM for gradient palette code (AVR).
// 1,494 bytes total for all 34 color palettes and associated code.
// Gradient palette "ib_jul01_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/xmas/tn/ib_jul01.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 16 bytes of program space.
DEFINE_GRADIENT_PALETTE( ib_jul01_gp ) {
0, 194, 1, 1,
94, 1, 29, 18,
132, 57,131, 28,
255, 113, 1, 1};
// Gradient palette "es_vintage_57_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/vintage/tn/es_vintage_57.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 20 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_vintage_57_gp ) {
0, 2, 1, 1,
53, 18, 1, 0,
104, 69, 29, 1,
153, 167,135, 10,
255, 46, 56, 4};
// Gradient palette "es_vintage_01_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/vintage/tn/es_vintage_01.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 32 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_vintage_01_gp ) {
0, 4, 1, 1,
51, 16, 0, 1,
76, 97,104, 3,
101, 255,131, 19,
127, 67, 9, 4,
153, 16, 0, 1,
229, 4, 1, 1,
255, 4, 1, 1};
// Gradient palette "es_rivendell_15_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/rivendell/tn/es_rivendell_15.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 20 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_rivendell_15_gp ) {
0, 1, 14, 5,
101, 16, 36, 14,
165, 56, 68, 30,
242, 150,156, 99,
255, 150,156, 99};
// Gradient palette "rgi_15_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/rgi/tn/rgi_15.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 36 bytes of program space.
DEFINE_GRADIENT_PALETTE( rgi_15_gp ) {
0, 4, 1, 31,
31, 55, 1, 16,
63, 197, 3, 7,
95, 59, 2, 17,
127, 6, 2, 34,
159, 39, 6, 33,
191, 112, 13, 32,
223, 56, 9, 35,
255, 22, 6, 38};
// Gradient palette "retro2_16_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ma/retro2/tn/retro2_16.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 8 bytes of program space.
DEFINE_GRADIENT_PALETTE( retro2_16_gp ) {
0, 188,135, 1,
255, 46, 7, 1};
// Gradient palette "Analogous_1_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/red/tn/Analogous_1.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 20 bytes of program space.
DEFINE_GRADIENT_PALETTE( Analogous_1_gp ) {
0, 3, 0,255,
63, 23, 0,255,
127, 67, 0,255,
191, 142, 0, 45,
255, 255, 0, 0};
// Gradient palette "es_pinksplash_08_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/pink_splash/tn/es_pinksplash_08.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 20 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_pinksplash_08_gp ) {
0, 126, 11,255,
127, 197, 1, 22,
175, 210,157,172,
221, 157, 3,112,
255, 157, 3,112};
// Gradient palette "es_pinksplash_07_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/pink_splash/tn/es_pinksplash_07.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 28 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_pinksplash_07_gp ) {
0, 229, 1, 1,
61, 242, 4, 63,
101, 255, 12,255,
127, 249, 81,252,
153, 255, 11,235,
193, 244, 5, 68,
255, 232, 1, 5};
// Gradient palette "Coral_reef_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/other/tn/Coral_reef.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 24 bytes of program space.
DEFINE_GRADIENT_PALETTE( Coral_reef_gp ) {
0, 40,199,197,
50, 10,152,155,
96, 1,111,120,
96, 43,127,162,
139, 10, 73,111,
255, 1, 34, 71};
// Gradient palette "es_ocean_breeze_068_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/ocean_breeze/tn/es_ocean_breeze_068.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 24 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_ocean_breeze_068_gp ) {
0, 100,156,153,
51, 1, 99,137,
101, 1, 68, 84,
104, 35,142,168,
178, 0, 63,117,
255, 1, 10, 10};
// Gradient palette "es_ocean_breeze_036_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/ocean_breeze/tn/es_ocean_breeze_036.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 16 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_ocean_breeze_036_gp ) {
0, 1, 6, 7,
89, 1, 99,111,
153, 144,209,255,
255, 0, 73, 82};
// Gradient palette "departure_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/mjf/tn/departure.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 88 bytes of program space.
DEFINE_GRADIENT_PALETTE( departure_gp ) {
0, 8, 3, 0,
42, 23, 7, 0,
63, 75, 38, 6,
84, 169, 99, 38,
106, 213,169,119,
116, 255,255,255,
138, 135,255,138,
148, 22,255, 24,
170, 0,255, 0,
191, 0,136, 0,
212, 0, 55, 0,
255, 0, 55, 0};
// Gradient palette "es_landscape_64_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/landscape/tn/es_landscape_64.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 36 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_landscape_64_gp ) {
0, 0, 0, 0,
37, 2, 25, 1,
76, 15,115, 5,
127, 79,213, 1,
128, 126,211, 47,
130, 188,209,247,
153, 144,182,205,
204, 59,117,250,
255, 1, 37,192};
// Gradient palette "es_landscape_33_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/landscape/tn/es_landscape_33.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 24 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_landscape_33_gp ) {
0, 1, 5, 0,
19, 32, 23, 1,
38, 161, 55, 1,
63, 229,144, 1,
66, 39,142, 74,
255, 1, 4, 1};
// Gradient palette "rainbowsherbet_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ma/icecream/tn/rainbowsherbet.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 28 bytes of program space.
DEFINE_GRADIENT_PALETTE( rainbowsherbet_gp ) {
0, 255, 33, 4,
43, 255, 68, 25,
86, 255, 7, 25,
127, 255, 82,103,
170, 255,255,242,
209, 42,255, 22,
255, 87,255, 65};
// Gradient palette "gr65_hult_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/hult/tn/gr65_hult.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 24 bytes of program space.
DEFINE_GRADIENT_PALETTE( gr65_hult_gp ) {
0, 247,176,247,
48, 255,136,255,
89, 220, 29,226,
160, 7, 82,178,
216, 1,124,109,
255, 1,124,109};
// Gradient palette "gr64_hult_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/hult/tn/gr64_hult.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 32 bytes of program space.
DEFINE_GRADIENT_PALETTE( gr64_hult_gp ) {
0, 1,124,109,
66, 1, 93, 79,
104, 52, 65, 1,
130, 115,127, 1,
150, 52, 65, 1,
201, 1, 86, 72,
239, 0, 55, 45,
255, 0, 55, 45};
// Gradient palette "GMT_drywet_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/gmt/tn/GMT_drywet.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 28 bytes of program space.
DEFINE_GRADIENT_PALETTE( GMT_drywet_gp ) {
0, 47, 30, 2,
42, 213,147, 24,
84, 103,219, 52,
127, 3,219,207,
170, 1, 48,214,
212, 1, 1,111,
255, 1, 7, 33};
// Gradient palette "ib15_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ing/general/tn/ib15.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 24 bytes of program space.
DEFINE_GRADIENT_PALETTE( ib15_gp ) {
0, 113, 91,147,
72, 157, 88, 78,
89, 208, 85, 33,
107, 255, 29, 11,
141, 137, 31, 39,
255, 59, 33, 89};
// Gradient palette "Fuschia_7_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/ds/fuschia/tn/Fuschia-7.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 20 bytes of program space.
DEFINE_GRADIENT_PALETTE( Fuschia_7_gp ) {
0, 43, 3,153,
63, 100, 4,103,
127, 188, 5, 66,
191, 161, 11,115,
255, 135, 20,182};
// Gradient palette "es_emerald_dragon_08_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/emerald_dragon/tn/es_emerald_dragon_08.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 16 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_emerald_dragon_08_gp ) {
0, 97,255, 1,
101, 47,133, 1,
178, 13, 43, 1,
255, 2, 10, 1};
// Gradient palette "lava_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/neota/elem/tn/lava.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 52 bytes of program space.
DEFINE_GRADIENT_PALETTE( lava_gp ) {
0, 0, 0, 0,
46, 18, 0, 0,
96, 113, 0, 0,
108, 142, 3, 1,
119, 175, 17, 1,
146, 213, 44, 2,
174, 255, 82, 4,
188, 255,115, 4,
202, 255,156, 4,
218, 255,203, 4,
234, 255,255, 4,
244, 255,255, 71,
255, 255,255,255};
// Gradient palette "fire_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/neota/elem/tn/fire.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 28 bytes of program space.
DEFINE_GRADIENT_PALETTE( fire_gp ) {
0, 1, 1, 0,
76, 32, 5, 0,
146, 192, 24, 0,
197, 220,105, 5,
240, 252,255, 31,
250, 252,255,111,
255, 255,255,255};
// Gradient palette "Colorfull_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Colorfull.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 44 bytes of program space.
DEFINE_GRADIENT_PALETTE( Colorfull_gp ) {
0, 10, 85, 5,
25, 29,109, 18,
60, 59,138, 42,
93, 83, 99, 52,
106, 110, 66, 64,
109, 123, 49, 65,
113, 139, 35, 66,
116, 192,117, 98,
124, 255,255,137,
168, 100,180,155,
255, 22,121,174};
// Gradient palette "Magenta_Evening_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Magenta_Evening.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 28 bytes of program space.
DEFINE_GRADIENT_PALETTE( Magenta_Evening_gp ) {
0, 71, 27, 39,
31, 130, 11, 51,
63, 213, 2, 64,
70, 232, 1, 66,
76, 252, 1, 69,
108, 123, 2, 51,
255, 46, 9, 35};
// Gradient palette "Pink_Purple_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Pink_Purple.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 44 bytes of program space.
DEFINE_GRADIENT_PALETTE( Pink_Purple_gp ) {
0, 19, 2, 39,
25, 26, 4, 45,
51, 33, 6, 52,
76, 68, 62,125,
102, 118,187,240,
109, 163,215,247,
114, 217,244,255,
122, 159,149,221,
149, 113, 78,188,
183, 128, 57,155,
255, 146, 40,123};
// Gradient palette "Sunset_Real_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/atmospheric/tn/Sunset_Real.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 28 bytes of program space.
DEFINE_GRADIENT_PALETTE( Sunset_Real_gp ) {
0, 120, 0, 0,
22, 179, 22, 0,
51, 255,104, 0,
85, 167, 22, 18,
135, 100, 0,103,
198, 16, 0,130,
255, 0, 0,160};
// Gradient palette "es_autumn_19_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/es/autumn/tn/es_autumn_19.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 52 bytes of program space.
DEFINE_GRADIENT_PALETTE( es_autumn_19_gp ) {
0, 26, 1, 1,
51, 67, 4, 1,
84, 118, 14, 1,
104, 137,152, 52,
112, 113, 65, 1,
122, 133,149, 59,
124, 137,152, 52,
135, 113, 65, 1,
142, 139,154, 46,
163, 113, 13, 1,
204, 55, 3, 1,
249, 17, 1, 1,
255, 17, 1, 1};
// Gradient palette "BlacK_Blue_Magenta_White_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/BlacK_Blue_Magenta_White.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 28 bytes of program space.
DEFINE_GRADIENT_PALETTE( BlacK_Blue_Magenta_White_gp ) {
0, 0, 0, 0,
42, 0, 0, 45,
84, 0, 0,255,
127, 42, 0,255,
170, 255, 0,255,
212, 255, 55,255,
255, 255,255,255};
// Gradient palette "BlacK_Magenta_Red_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/BlacK_Magenta_Red.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 20 bytes of program space.
DEFINE_GRADIENT_PALETTE( BlacK_Magenta_Red_gp ) {
0, 0, 0, 0,
63, 42, 0, 45,
127, 255, 0,255,
191, 255, 0, 45,
255, 255, 0, 0};
// Gradient palette "BlacK_Red_Magenta_Yellow_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/BlacK_Red_Magenta_Yellow.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 28 bytes of program space.
DEFINE_GRADIENT_PALETTE( BlacK_Red_Magenta_Yellow_gp ) {
0, 0, 0, 0,
42, 42, 0, 0,
84, 255, 0, 0,
127, 255, 0, 45,
170, 255, 0,255,
212, 255, 55, 45,
255, 255,255, 0};
// Gradient palette "Blue_Cyan_Yellow_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/nd/basic/tn/Blue_Cyan_Yellow.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 20 bytes of program space.
DEFINE_GRADIENT_PALETTE( Blue_Cyan_Yellow_gp ) {
0, 0, 0,255,
63, 0, 55,255,
127, 0,255,255,
191, 42,255, 45,
255, 255,255, 0};
// Gradient palette "bhw1_28_gp", originally from
// http://soliton.vm.bytemark.co.uk/pub/cpt-city/bhw/bhw1/tn/bhw1_28.png.index.html
// converted for FastLED with gammas (2.6, 2.2, 2.5)
// Size: 32 bytes of program space.
DEFINE_GRADIENT_PALETTE( bhw1_28_gp ) {
0, 75, 1,221,
30, 252, 73,255,
48, 169, 0,242,
119, 0,149,242,
170, 43, 0,242,
206, 252, 73,255,
232, 78, 12,214,
255, 0,149,242};
// Single array of defined cpt-city color palettes.
// This will let us programmatically choose one based on
// a number, rather than having to activate each explicitly
// by name every time.
// Since it is const, this array could also be moved
// into PROGMEM to save SRAM, but for simplicity of illustration
// we'll keep it in a regular SRAM array.
//
// This list of color palettes acts as a "playlist"; you can
// add or delete, or re-arrange as you wish.
const TProgmemRGBGradientPalettePtr gGradientPalettes[] = {
bhw1_28_gp,
Sunset_Real_gp,
es_rivendell_15_gp,
es_ocean_breeze_036_gp,
rgi_15_gp,
retro2_16_gp,
Analogous_1_gp,
es_pinksplash_08_gp,
Coral_reef_gp,
es_ocean_breeze_068_gp,
es_pinksplash_07_gp,
es_vintage_01_gp,
departure_gp,
es_landscape_64_gp,
es_landscape_33_gp,
rainbowsherbet_gp,
gr65_hult_gp,
gr64_hult_gp,
GMT_drywet_gp,
ib_jul01_gp,
es_vintage_57_gp,
ib15_gp,
Fuschia_7_gp,
es_emerald_dragon_08_gp,
lava_gp,
fire_gp,
Colorfull_gp,
Magenta_Evening_gp,
Pink_Purple_gp,
es_autumn_19_gp,
BlacK_Blue_Magenta_White_gp,
BlacK_Magenta_Red_gp,
BlacK_Red_Magenta_Yellow_gp,
Blue_Cyan_Yellow_gp };
// Count of how many cpt-city gradients are defined:
const uint8_t gGradientPaletteCount =
sizeof( gGradientPalettes) / sizeof( TProgmemRGBGradientPalettePtr );
void loop()
{
EVERY_N_SECONDS( SECONDS_PER_PALETTE ) {
gCurrentPaletteNumber = addmod8( gCurrentPaletteNumber, 1, gGradientPaletteCount);
gTargetPalette = gGradientPalettes[ gCurrentPaletteNumber ];
}
EVERY_N_MILLISECONDS(40) {
nblendPaletteTowardPalette( gCurrentPalette, gTargetPalette, 16);
}
colorwaves( leds, NUM_LEDS, gCurrentPalette);
FastLED.show();
FastLED.delay(20);
}