Skip to content

Instantly share code, notes, and snippets.

@debsahu
Last active February 2, 2019 23:53
Show Gist options
  • Save debsahu/297b5416a870a84410a303b8760a48e2 to your computer and use it in GitHub Desktop.
Save debsahu/297b5416a870a84410a303b8760a48e2 to your computer and use it in GitHub Desktop.
#include <Adafruit_DotStar.h>
#include <SPI.h> // COMMENT OUT THIS LINE FOR GEMMA OR TRINKET
#define NUMPIXELS 30 // Number of LEDs in strip
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG);
void setup() {
Serial.print("Hardware SPI using DATA PIN: ");
Serial.println(MOSI);
Serial.print("Hardware SPI using CLOCK PIN: ");
Serial.println(SCK);
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 = -10; // Index of first 'on' and 'off' pixels
uint32_t color = 0xFF0000; // 'On' color (starts red)
void loop() {
strip.setPixelColor(head, color); // 'On' pixel at head
strip.setPixelColor(tail, 0); // 'Off' pixel at tail
strip.show(); // Refresh strip
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