|
| 1 | +// SPDX-FileCopyrightText: 2023 Phil B. for Adafruit Industries |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +#include <seesaw_neopixel.h> |
| 5 | +#define PIN 15 |
| 6 | + |
| 7 | +// Parameter 1 = number of pixels in strip |
| 8 | +// Parameter 2 = Arduino pin number (most are valid) |
| 9 | +// Parameter 3 = pixel type flags, add together as needed: |
| 10 | +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) |
| 11 | +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) |
| 12 | +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) |
| 13 | +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) |
| 14 | +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) |
| 15 | +seesaw_NeoPixel strip = seesaw_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800); |
| 16 | + |
| 17 | +// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across |
| 18 | +// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input |
| 19 | +// and minimize distance between Arduino and first pixel. Avoid connecting |
| 20 | +// on a live circuit...if you must, connect GND first. |
| 21 | + |
| 22 | +void setup() { |
| 23 | + Serial.begin(115200); |
| 24 | + |
| 25 | + while (!Serial) delay(10); // wait until serial port is opened |
| 26 | + |
| 27 | + if(!strip.begin(0x60)){ |
| 28 | + Serial.println("seesaw not found!"); |
| 29 | + while(1) delay(10); |
| 30 | + } |
| 31 | + |
| 32 | + Serial.println(F("seesaw started OK!")); |
| 33 | + |
| 34 | + strip.show(); // Initialize all pixels to 'off' |
| 35 | +} |
| 36 | + |
| 37 | +void loop() { |
| 38 | + rainbowCycle(20); |
| 39 | + |
| 40 | +} |
| 41 | + |
| 42 | +void rainbow(uint8_t wait) { |
| 43 | + uint16_t i, j; |
| 44 | + |
| 45 | + for(j=0; j<256; j++) { |
| 46 | + for(i=0; i<strip.numPixels(); i++) { |
| 47 | + strip.setPixelColor(i, Wheel((i+j) & 255)); |
| 48 | + } |
| 49 | + strip.show(); |
| 50 | + delay(wait); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +// Slightly different, this makes the rainbow equally distributed throughout |
| 55 | +void rainbowCycle(uint8_t wait) { |
| 56 | + uint16_t i, j; |
| 57 | + |
| 58 | + for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel |
| 59 | + for(i=0; i< strip.numPixels(); i++) { |
| 60 | + strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); |
| 61 | + } |
| 62 | + strip.show(); |
| 63 | + delay(wait); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +// Input a value 0 to 255 to get a color value. |
| 68 | +// The colours are a transition r - g - b - back to r. |
| 69 | +uint32_t Wheel(byte WheelPos) { |
| 70 | + WheelPos = 255 - WheelPos; |
| 71 | + if(WheelPos < 85) { |
| 72 | + return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); |
| 73 | + } |
| 74 | + if(WheelPos < 170) { |
| 75 | + WheelPos -= 85; |
| 76 | + return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); |
| 77 | + } |
| 78 | + WheelPos -= 170; |
| 79 | + return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); |
| 80 | +} |
0 commit comments