Created
April 9, 2017 19:20
-
-
Save kindanduseful/ab2f3d3d7ba1cfe32f387bf420abd1a0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple strand test for Adafruit Dot Star RGB LED strip. | |
// This is a basic diagnostic tool, NOT a graphics demo...helps confirm | |
// correct wiring and tests each pixel's ability to display red, green | |
// and blue and to forward data down the line. By limiting the number | |
// and color of LEDs, it's reasonably safe to power a couple meters off | |
// the Arduino's 5V pin. DON'T try that with other code! | |
#include <Adafruit_DotStar.h> | |
// Because conditional #includes don't work w/Arduino sketches... | |
#include <SPI.h> // COMMENT OUT THIS LINE FOR GEMMA OR TRINKET | |
//#include <avr/power.h> // ENABLE THIS LINE FOR GEMMA OR TRINKET | |
#define NUMPIXELS 2 // Number of LEDs in strip | |
// Here's how to control the LEDs from any two pins: | |
#define DATAPIN 4 | |
#define CLOCKPIN 5 | |
Adafruit_DotStar strip = Adafruit_DotStar( | |
NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG); | |
// The last parameter is optional -- this is the color data order of the | |
// DotStar strip, which has changed over time in different production runs. | |
// Your code just uses R,G,B colors, the library then reassigns as needed. | |
// Default is DOTSTAR_BRG, so change this if you have an earlier strip. | |
// Hardware SPI is a little faster, but must be wired to specific pins | |
// (Arduino Uno = pin 11 for data, 13 for clock, other boards are different). | |
//Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG); | |
void setup() { | |
//#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L) | |
// clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket | |
//#endif | |
strip.begin(); // Initialize pins for output | |
strip.show(); // Turn all LEDs off ASAP | |
} | |
// Runs 10 LEDs at a time along strip, cycling through red, green and blue. | |
// This requires about 200 mA for all the 'on' pixels + 1 mA per 'off' pixel. | |
//int head = 0, tail = -1; // Index of first 'on' and 'off' pixels | |
void loop() { | |
//for(byte x=0;x<2;x++) | |
//{ | |
//strip.setPixelColor(x,color); | |
//} | |
//strip.show(); | |
//delay(20); | |
int mint = 60; | |
int maxt = 300; | |
uint32_t color = 0xFFFF00; // 'On' color (starts red) | |
strip.setPixelColor(0, color); // 'On' pixel at head | |
strip.setPixelColor(1, color); // 'On' pixel at head | |
delay(random(mint,maxt)); | |
strip.show(); // Refresh strip | |
uint32_t color1 = 0x88CC00; // 'On' color (starts red) | |
strip.setPixelColor(0, color1); // 'On' pixel at head | |
strip.setPixelColor(1, color1); // 'On' pixel at head | |
delay(random(mint,maxt)); | |
strip.show(); // Refresh strip | |
uint32_t color2 = 0x004400; // 'On' color (starts red) | |
strip.setPixelColor(0, color2); // 'On' pixel at head | |
strip.setPixelColor(1, color2); // 'On' pixel at head | |
delay(random(mint,maxt)); | |
strip.show(); // Refresh strip | |
strip.setPixelColor(0, color1); // 'On' pixel at head | |
strip.setPixelColor(1, color1); // 'On' pixel at head | |
delay(random(mint,maxt)); | |
strip.show(); // Refresh strip | |
// strip.setPixelColor(tail, 0); // 'Off' pixel at tail | |
//delay(20); // Pause 20 milliseconds (~50 FPS) | |
// | |
// if(++head >= NUMPIXELS) { // Increment head index. Off end of strip? | |
// head = 0; // Yes, reset head index to start | |
// if((color >>= 8) == 0) // Next color (R->G->B) ... past blue now? | |
// color = 0xFF0000; // Yes, reset to red | |
// } | |
// if(++tail >= NUMPIXELS) tail = 0; // Increment, reset tail index | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment