From f22327bd129dee5b6999e802ffd7ca1a85c31aac Mon Sep 17 00:00:00 2001 From: Phillip Burgess Date: Thu, 28 Sep 2017 12:37:23 -0700 Subject: [PATCH] Add code for several projects, remove test folder --- .../Gemma_3D_Printed_Tree_Topper.ino | 61 ++++++++++++++ .../Gemma_3D_Printed_Tree_Topper.py | 47 +++++++++++ Gemma_3D_Printed_Tree_Topper/README.md | 4 + .../Mystical_LED_Halloween_Hood.ino | 66 +++++++++++++++ .../Mystical_LED_Halloween_Hood.py | 36 +++++++++ Mystical_LED_Halloween_Hood/README.md | 4 + NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.ino | 77 ++++++++++++++++++ NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.py | 80 +++++++++++++++++++ NeoPixel_Blinkendisc/README.md | 4 + .../Figure_Eight.ino | 37 +++++++++ NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py | 27 +++++++ NeoPixel_Ring_Bangle_Bracelet/README.md | 4 + .../Random_Flash.ino | 69 ++++++++++++++++ NeoPixel_Ring_Bangle_Bracelet/Random_Flash.py | 28 +++++++ NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.ino | 35 ++++++++ NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py | 25 ++++++ Superhero_Power_Plant/README.md | 4 + .../Superhero_Power_Plant.ino | 65 +++++++++++++++ .../Superhero_Power_Plant.py | 36 +++++++++ This_is_a_Guide_Title/This_is_Guide_Code.py | 3 - 20 files changed, 709 insertions(+), 3 deletions(-) create mode 100644 Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.ino create mode 100644 Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.py create mode 100644 Gemma_3D_Printed_Tree_Topper/README.md create mode 100644 Mystical_LED_Halloween_Hood/Mystical_LED_Halloween_Hood.ino create mode 100644 Mystical_LED_Halloween_Hood/Mystical_LED_Halloween_Hood.py create mode 100644 Mystical_LED_Halloween_Hood/README.md create mode 100644 NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.ino create mode 100644 NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.py create mode 100644 NeoPixel_Blinkendisc/README.md create mode 100644 NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.ino create mode 100644 NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py create mode 100644 NeoPixel_Ring_Bangle_Bracelet/README.md create mode 100644 NeoPixel_Ring_Bangle_Bracelet/Random_Flash.ino create mode 100644 NeoPixel_Ring_Bangle_Bracelet/Random_Flash.py create mode 100644 NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.ino create mode 100644 NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py create mode 100644 Superhero_Power_Plant/README.md create mode 100644 Superhero_Power_Plant/Superhero_Power_Plant.ino create mode 100644 Superhero_Power_Plant/Superhero_Power_Plant.py delete mode 100644 This_is_a_Guide_Title/This_is_Guide_Code.py diff --git a/Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.ino b/Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.ino new file mode 100644 index 000000000..c52205ecd --- /dev/null +++ b/Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.ino @@ -0,0 +1,61 @@ +#include + +#define PIN 1 +#define NUM_LEDS 36 + +Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, PIN); + +uint8_t mode = 0, // Current animation effect + offset = 0; // Position of spinner animation +uint32_t color = 0xA000A0; // Purple +uint32_t prevTime; // Time of last animation mode switch + +void setup() { + pixels.begin(); + pixels.setBrightness(255); // Full brightness + prevTime = millis(); // Starting time +} + +void loop() { + uint8_t i; + uint32_t t; + + switch(mode) { + + case 0: // Random sparkles - just one LED on at a time! + i = random(NUM_LEDS); // Choose a random pixel + pixels.setPixelColor(i, color); // Set it to current color + pixels.show(); // Refresh LED states + // Set same pixel to "off" color now but DON'T refresh... + // it stays on for now...both this and the next random + // pixel will be refreshed on the next pass. + pixels.setPixelColor(i, 0); + delay(10); // 10 millisecond delay + break; + + case 1: // Spinny wheel + for(i=0; i 8000) { // Every 8 seconds... + mode++; // Advance to next animation mode + if(mode > 1) { // End of modes? + mode = 0; // Start over from beginning + } + pixels.clear(); // Set all pixels to 'off' state + prevTime = t; // Record the time of the last mode change + } +} diff --git a/Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.py b/Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.py new file mode 100644 index 000000000..6d88f2033 --- /dev/null +++ b/Gemma_3D_Printed_Tree_Topper/Gemma_3D_Printed_Tree_Topper.py @@ -0,0 +1,47 @@ +import board +import neopixel +import time +try: + import urandom as random # for v1.0 API support +except ImportError: + import random + +numpix = 36 # Number of NeoPixels +pixpin = board.D1 # Pin where NeoPixels are connected +strip = neopixel.NeoPixel(pixpin, numpix, brightness=1.0) + +mode = 0 # Current animation effect +offset = 0 # Position of spinner animation +color = [160, 0, 160] # RGB color - purple +prevtime = time.monotonic() # Time of last animation mode switch + +while True: # Loop forever... + + if mode == 0: # Random sparkles - lights just one LED at a time + i = random.randint(0, numpix - 1) # Choose random pixel + strip[i] = color # Set it to current color + strip.write() # Refresh LED states + # Set same pixel to "off" color now but DON'T refresh... + # it stays on for now...bot this and the next random + # pixel will be refreshed on the next pass. + strip[i] = [0,0,0] + time.sleep(0.008) # 8 millisecond delay + elif mode == 1: # Spinny wheel (4 LEDs on at a time) + for i in range(numpix): # For each LED... + if ((offset + i) & 7) < 2: # 2 pixels out of 8... + strip[i] = color # are set to current color + else: + strip[i] = [0,0,0] # other pixels are off + strip.write() # Refresh LED states + time.sleep(0.08) # 80 millisecond delay + offset += 1 # Shift animation by 1 pixel on next frame + if offset >= 8: offset = 0 + # Additional animation modes could be added here! + + t = time.monotonic() # Current time in seconds + if (t - prevtime) >= 8: # Every 8 seconds... + mode += 1 # Advance to next mode + if mode > 1: # End of modes? + mode = 0 # Start over from beginning + strip.fill([0,0,0]) # Turn off all pixels + prevtime = t # Record time of last mode change diff --git a/Gemma_3D_Printed_Tree_Topper/README.md b/Gemma_3D_Printed_Tree_Topper/README.md new file mode 100644 index 000000000..c6ad62c6a --- /dev/null +++ b/Gemma_3D_Printed_Tree_Topper/README.md @@ -0,0 +1,4 @@ +# Gemma_3D_Printed_Tree_Topper + +Code to accompany this tutorial: +https://learn.adafruit.com/gemma-3d-printed-tree-topper diff --git a/Mystical_LED_Halloween_Hood/Mystical_LED_Halloween_Hood.ino b/Mystical_LED_Halloween_Hood/Mystical_LED_Halloween_Hood.ino new file mode 100644 index 000000000..aa8a8fa67 --- /dev/null +++ b/Mystical_LED_Halloween_Hood/Mystical_LED_Halloween_Hood.ino @@ -0,0 +1,66 @@ +//fades all pixels subtly +//code by Tony Sherwood for Adafruit Industries + +#include + +#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(14, PIN, NEO_GRB + NEO_KHZ800); + +int alpha; // Current value of the pixels +int dir = 1; // Direction of the pixels... 1 = getting brighter, 0 = getting dimmer +int flip; // Randomly flip the direction every once in a while +int minAlpha = 25; // Min value of brightness +int maxAlpha = 100; // Max value of brightness +int alphaDelta = 5; // Delta of brightness between times through the loop + +void setup() { + strip.begin(); + strip.show(); // Initialize all pixels to 'off' +} + +void loop() { + flip = random(32); + if(flip > 20) { + dir = 1 - dir; + } + // Some example procedures showing how to display to the pixels: + if (dir == 1) { + alpha += alphaDelta; + } + if (dir == 0) { + alpha -= alphaDelta; + } + if (alpha < minAlpha) { + alpha = minAlpha; + dir = 1; + } + if (alpha > maxAlpha) { + alpha = maxAlpha; + dir = 0; + } + // Change the line below to alter the color of the lights + // The numbers represent the Red, Green, and Blue values + // of the lights, as a value between 0(off) and 1(max brightness) + // + // EX: + // colorSet(strip.Color(alpha, 0, alpha/2)); // Pink + //colorSet(strip.Color(0, 0, alpha)); // Blue + //colorSet(strip.Color(alpha, alpha/2, 0)); // Yellow + colorSet(strip.Color(alpha, 0, 0)); // Red +} + +// Fill the dots one after the other with a color +void colorSet(uint32_t c) { + for(uint16_t i=0; i= maxAlpha: # At or above max? + alpha = maxAlpha # Limit to max + alphaUp = False # and switch direction + else: # Else decreasing brightness + alpha -= alphaDelta # Subtract some amount + if alpha <= minAlpha: # At or below min? + alpha = minAlpha # Limit to min + alphaUp = True # and switch direction + + strip.brightness = alpha # Set brightness to 0.0 to 1.0 + strip.write() # and issue data to LED strip diff --git a/Mystical_LED_Halloween_Hood/README.md b/Mystical_LED_Halloween_Hood/README.md new file mode 100644 index 000000000..9a3310f82 --- /dev/null +++ b/Mystical_LED_Halloween_Hood/README.md @@ -0,0 +1,4 @@ +# Mystical_LED_Halloween_Hood + +Code to accompany this tutorial: +https://learn.adafruit.com/mystical-led-halloween-hood diff --git a/NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.ino b/NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.ino new file mode 100644 index 000000000..a75a3bb79 --- /dev/null +++ b/NeoPixel_Blinkendisc/NeoPixel_Blinkendisc.ino @@ -0,0 +1,77 @@ +#include + +#define NUM_LEDS 24 // 24 LED NeoPixel ring +#define NEOPIXEL_PIN 0 // Pin D0 on Gemma +#define VIBRATION_PIN 1 // Pin D1 on Gemma +#define ANALOG_RANDOMNESS_PIN A1 // Not connected to anything + +#define DEFAULT_FRAME_LEN 60 +#define MAX_FRAME_LEN 255 +#define MIN_FRAME_LEN 5 +#define COOLDOWN_AT 2000 +#define DIM_AT 2500 +#define BRIGHTNESS_HIGH 128 +#define BRIGHTNESS_LOW 32 + +Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUM_LEDS, NEOPIXEL_PIN); + +uint32_t color = pixels.Color(0, 120, 30); +uint8_t offset = 0; +uint8_t frame_len = DEFAULT_FRAME_LEN; +uint32_t last_vibration = 0; +uint32_t last_frame = 0; + +void setup() { + // Random number generator is seeded from an unused 'floating' + // analog input - this helps ensure the random color choices + // aren't always the same order. + randomSeed(analogRead(ANALOG_RANDOMNESS_PIN)); + // Enable pullup on vibration switch pin. When the switch + // is activated, it's pulled to ground (LOW). + pinMode(VIBRATION_PIN, INPUT_PULLUP); + pixels.begin(); +} + +void loop() { + uint32_t t; + + // Compare millis() against lastFrame time to keep frame-to-frame + // animation timing consistent. Use this idle time to check the + // vibration switch for activity. + while(((t = millis()) - last_frame) <= frame_len) { + if(!digitalRead(VIBRATION_PIN)) { // Vibration sensor activated? + color = pixels.Color( // Pick a random RGB color + random(256), // red + random(256), // green + random(256) // blue + ); + frame_len = DEFAULT_FRAME_LEN; // Reset frame timing to default + last_vibration = t; // Save last vibration time + } + } + + // Stretch out frames if nothing has happened in a couple of seconds: + if((t - last_vibration) > COOLDOWN_AT) { + if(++frame_len > MAX_FRAME_LEN) frame_len = MIN_FRAME_LEN; + } + + // If we haven't registered a vibration in DIM_AT ms, go dim: + if((t - last_vibration) > DIM_AT) { + pixels.setBrightness(BRIGHTNESS_LOW); + } else { + pixels.setBrightness(BRIGHTNESS_HIGH); + } + + // Erase previous pixels and light new ones: + pixels.clear(); + for(int i=0; i= frame_len: break + if not pin.value: # Vibration switch activated? + color = [ # Pick a random RGB color... + random.randint(32, 255), + random.randint(32, 255), + random.randint(32, 255) ] + frame_len = default_frame_len # Reset frame timing + last_vibration = t # Save last trigger time + + # Stretch out frames if nothing has happened in a couple of seconds: + if((t - last_vibration) > cooldown_at): + frame_len += 0.001 # Add 1 ms + if frame_len > max_frame_len: frame_len = min_frame_len + + # If we haven't registered a vibration in dim_at ms, go dim: + if (t - last_vibration) > dim_at: + strip.brightness = brightness_low + else: + strip.brightness = brightness_high + + # Erase previous pixels and light new ones: + strip.fill( [0, 0, 0] ) + for i in range(0, num_leds, 6): + strip[(offset + i) % num_leds] = color + + strip.write() # and issue data to LED strip + + # Increase pixel offset until it hits 6, then roll back to 0: + offset = (offset + 1) % 6 + + last_frame = t diff --git a/NeoPixel_Blinkendisc/README.md b/NeoPixel_Blinkendisc/README.md new file mode 100644 index 000000000..52323087b --- /dev/null +++ b/NeoPixel_Blinkendisc/README.md @@ -0,0 +1,4 @@ +# NeoPixel_Blinkendisc + +Code to accompany this tutorial: +https://learn.adafruit.com/a-neopixel-blinkendisc diff --git a/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.ino b/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.ino new file mode 100644 index 000000000..ec5ea0dec --- /dev/null +++ b/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.ino @@ -0,0 +1,37 @@ +//Figure-Eight animation for Neopixel Ring Bangle Bracelet +//By Dano Wall and Becky Stern for Adafruit Industries +#include + +#define PIN 1 // Marked D1 on GEMMA +#define NUM_LEDS 64 + +// Parameter 1 = number of pixels in strip +// Parameter 2 = pin number (most are valid) +// Parameter 3 = pixel type: +// 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(NUM_LEDS, PIN, NEO_GRB); + +uint32_t color = strip.Color(5, 250, 200); // Change RGB color value here + +// Array of pixels in order of animation - 70 in total: +int sine[] = { + 4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 48, 49, 50, 51, 52, 44, 43, 42, 41, 40, 39, 38, 37, 36, 28, + 29, 30, 31, 16, 17, 18, 19, 20, 12, 11, 10, 9, 8, 7, 6, 5 }; + +void setup() { + strip.begin(); + strip.show(); // Initialize all pixels to 'off' + strip.setBrightness(40); // 40/255 brightness (about 15%) +} + +void loop() { + for(int i=0; i<70; i++) { + strip.setPixelColor(sine[i], 0); // Erase 'tail' + strip.setPixelColor(sine[(i + 10) % 70], color); // Draw 'head' pixel + strip.show(); + delay(60); + } +} diff --git a/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py b/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py new file mode 100644 index 000000000..d4702e097 --- /dev/null +++ b/NeoPixel_Ring_Bangle_Bracelet/Figure_Eight.py @@ -0,0 +1,27 @@ +import board +import neopixel +import time +try: + import urandom as random +except ImportError: + import random + +numpix = 64 # Number of NeoPixels +pixpin = board.D1 # Pin where NeoPixels are connected +strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15) +color = [5, 250, 200] # RGB color - cyan + +sine = [ # These are the pixels in order of animation - 70 pixels in total: + 4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60, + 61, 62, 63, 48, 49, 50, 51, 52, 44, 43, 42, 41, 40, 39, 38, 37, 36, 28, + 29, 30, 31, 16, 17, 18, 19, 20, 12, 11, 10, 9, 8, 7, 6, 5 ] + +while True: # Loop forever... + for i in range(len(sine)): + # Erase 'tail': + strip[sine[i]] = [0,0,0] + # Draw 'head,' 10 pixels ahead: + strip[sine[(i + 10) % len(sine)]] = color + strip.write() # Refresh LED states + time.sleep(0.04) # 40 millisecond delay diff --git a/NeoPixel_Ring_Bangle_Bracelet/README.md b/NeoPixel_Ring_Bangle_Bracelet/README.md new file mode 100644 index 000000000..1158b125d --- /dev/null +++ b/NeoPixel_Ring_Bangle_Bracelet/README.md @@ -0,0 +1,4 @@ +# NeoPixel_Ring_Bangle_Bracelet + +Code to accompany this tutorial: +https://learn.adafruit.com/neopixel-ring-bangle-bracelet diff --git a/NeoPixel_Ring_Bangle_Bracelet/Random_Flash.ino b/NeoPixel_Ring_Bangle_Bracelet/Random_Flash.ino new file mode 100644 index 000000000..3bdf625b1 --- /dev/null +++ b/NeoPixel_Ring_Bangle_Bracelet/Random_Flash.ino @@ -0,0 +1,69 @@ +//Random Flash animation for Neopixel Ring Bangle Bracelet +//by Dano Wall and Becky Stern for Adafruit Industries +//based on the Sparkle Skirt, minus the accelerometer +#include + +#define PIN 1 // Marked D1 on GEMMA +#define NUM_LEDS 64 + +// Parameter 1 = number of pixels in strip +// Parameter 2 = pin number (most are valid) +// Parameter 3 = pixel type: +// 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(NUM_LEDS, PIN, NEO_GRB); + +// 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 +uint8_t myColors[][3] = { + {232, 100, 255}, // purple + {200, 200, 20}, // yellow + { 30, 200, 200}, // blue +}; + +// don't edit the line below +#define FAVCOLORS sizeof(myColors) / 3 + +void setup() { + strip.begin(); + strip.show(); // Initialize all pixels to 'off' + strip.setBrightness(40); // 40/255 brightness (about 15%) +} + +void loop() { + flashRandom(5); // Number is 'wait' delay, smaller num = faster twinkle +} + +void flashRandom(int wait) { + + // pick a random favorite color! + int c = random(FAVCOLORS); + int red = myColors[c][0]; + int green = myColors[c][1]; + int blue = myColors[c][2]; + + // get a random pixel from the list + int j = random(strip.numPixels()); + + // now we will fade in over 5 steps + for (int x=1; x <= 5; x++) { + int r = red * x / 5; + int g = green * x / 5; + int b = blue * x / 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 / 5; + int g = green * x / 5; + int b = blue * x / 5; + + strip.setPixelColor(j, strip.Color(r, g, b)); + strip.show(); + delay(wait); + } + // LED will be off when done (they are faded to 0) +} diff --git a/NeoPixel_Ring_Bangle_Bracelet/Random_Flash.py b/NeoPixel_Ring_Bangle_Bracelet/Random_Flash.py new file mode 100644 index 000000000..022a0821a --- /dev/null +++ b/NeoPixel_Ring_Bangle_Bracelet/Random_Flash.py @@ -0,0 +1,28 @@ +import board +import neopixel +import time +try: + import urandom as random +except ImportError: + import random + +numpix = 64 # Number of NeoPixels +pixpin = board.D1 # Pin where NeoPixels are connected +strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.0) +colors = [ + [ 232, 100, 255 ], # Purple + [ 200, 200, 20 ], # Yellow + [ 30, 200, 200 ], # Blue +] + +while True: # Loop forever... + c = random.randint(0, len(colors) - 1) # Choose random color index + j = random.randint(0, numpix - 1) # Choose random pixel + strip[j] = colors[c] # Set pixel to color + for i in range(1, 5): + strip.brightness = i / 5.0 # Ramp up brightness + strip.write() + for i in range(5, 0, -1): + strip.brightness = i / 5.0 # Ramp down brightness + strip.write() + strip[j] = [0,0,0] # Set pixel to 'off' diff --git a/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.ino b/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.ino new file mode 100644 index 000000000..8259d8b9a --- /dev/null +++ b/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.ino @@ -0,0 +1,35 @@ +//Basic sine wave animation for NeoPixel Ring Bangle Bracelet +//by Dano Wall and Becky Stern for Adafruit Industries +#include + +#define PIN 1 // Marked D1 on GEMMA +#define NUM_LEDS 64 + +// Parameter 1 = number of pixels in strip +// Parameter 2 = pin number (most are valid) +// Parameter 3 = pixel type: +// 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(NUM_LEDS, PIN, NEO_GRB); + +uint32_t color = strip.Color(75, 250, 100); // Change RGB color value here + +// These are the pixels in order of animation-- 36 pixels in total: +int sine[] = { + 4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60 }; + +void setup() { + strip.begin(); + strip.show(); // Initialize all pixels to 'off' + strip.setBrightness(40); // 40/255 brightness (about 15%) +} + +void loop() { + for(int i=0; i<36; i++) { + strip.setPixelColor(sine[i], color); // Draw 'head' pixel + strip.setPixelColor(sine[(i + 36 - 8) % 36], 0); // Erase 'tail' + strip.show(); + delay(40); + } +} diff --git a/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py b/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py new file mode 100644 index 000000000..d47330119 --- /dev/null +++ b/NeoPixel_Ring_Bangle_Bracelet/Sine_Wave.py @@ -0,0 +1,25 @@ +import board +import neopixel +import time +try: + import urandom as random # for v1.0 API support +except ImportError: + import random + +numpix = 64 # Number of NeoPixels +pixpin = board.D1 # Pin where NeoPixels are connected +strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15) +color = [75, 250, 100] # RGB color - teal + +sine = [ # These are the pixels in order of animation - 36 pixels in total: + 4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60 ] + +while True: # Loop forever... + for i in range(len(sine)): + # Set 'head' pixel to color: + strip[sine[i]] = color + # Erase 'tail,' 8 pixels back: + strip[sine[(i + len(sine) - 8) % len(sine)]] = [0,0,0] + strip.write() # Refresh LED states + time.sleep(0.016) # 16 millisecond delay diff --git a/Superhero_Power_Plant/README.md b/Superhero_Power_Plant/README.md new file mode 100644 index 000000000..62aee19dc --- /dev/null +++ b/Superhero_Power_Plant/README.md @@ -0,0 +1,4 @@ +# Superhero_Power_Plant + +Code to accompany this tutorial: +https://learn.adafruit.com/superhero-power-plant diff --git a/Superhero_Power_Plant/Superhero_Power_Plant.ino b/Superhero_Power_Plant/Superhero_Power_Plant.ino new file mode 100644 index 000000000..89583c80e --- /dev/null +++ b/Superhero_Power_Plant/Superhero_Power_Plant.ino @@ -0,0 +1,65 @@ +//Superhero Power Plant +//fades all pixels subtly +//code by Tony Sherwood for Adafruit Industries + +#include + +#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(17, PIN, NEO_GRB + NEO_KHZ800); + +int alpha; // Current value of the pixels +int dir = 1; // Direction of the pixels... 1 = getting brighter, 0 = getting dimmer +int flip; // Randomly flip the direction every once in a while +int minAlpha = 25; // Min value of brightness +int maxAlpha = 100; // Max value of brightness +int alphaDelta = 5; // Delta of brightness between times through the loop + +void setup() { + strip.begin(); + strip.show(); // Initialize all pixels to 'off' +} + +void loop() { + flip = random(32); + if(flip > 20) { + dir = 1 - dir; + } + // Some example procedures showing how to display to the pixels: + if (dir == 1) { + alpha += alphaDelta; + } + if (dir == 0) { + alpha -= alphaDelta; + } + if (alpha < minAlpha) { + alpha = minAlpha; + dir = 1; + } + if (alpha > maxAlpha) { + alpha = maxAlpha; + dir = 0; + } + // Change the line below to alter the color of the lights + // The numbers represent the Red, Green, and Blue values + // of the lights, as a value between 0(off) and 1(max brightness) + // + // EX: + // colorWipe(strip.Color(alpha, 0, alpha/2)); // Pink + colorWipe(strip.Color(0, 0, alpha)); // Blue +} + +// Fill the dots one after the other with a color +void colorWipe(uint32_t c) { + for(uint16_t i=0; i= maxAlpha: # At or above max? + alpha = maxAlpha # Limit to max + alphaUp = False # and switch direction + else: # Else decreasing brightness + alpha -= alphaDelta # Subtract some amount + if alpha <= minAlpha: # At or below min? + alpha = minAlpha # Limit to min + alphaUp = True # and switch direction + + strip.brightness = alpha # Set brightness to 0.0 to 1.0 + strip.write() # and issue data to LED strip diff --git a/This_is_a_Guide_Title/This_is_Guide_Code.py b/This_is_a_Guide_Title/This_is_Guide_Code.py deleted file mode 100644 index 358734905..000000000 --- a/This_is_a_Guide_Title/This_is_Guide_Code.py +++ /dev/null @@ -1,3 +0,0 @@ -Testing 1 2 3 -Look at this code -Look at it!