You can copy / paste the code below if you’re having issues with typos or want a shortcut. However I recommend that you follow along in the tutorial to understand what is going on!
simpleon.ino
#include <Adafruit_DotStar.h>
#include <SPI.h>
#define NUMPIXELS 30
// Create the strip
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG) ;
void simpleOn(uint32_t color, uint8_t head, uint8_t tail) {
for (int i=(tail-1); i < head; i++){
strip.setPixelColor(i, color) ;
}
strip.show() ;
}
void setup() {
strip.begin() ;
strip.show() ; // This turns off the LEDs within NUMPIXELS
}
void loop() {
uint8_t head, tail ;
uint32_t color ;
color = 0x1577D5 ;
head = 7 ;
tail = 2 ;
simpleOn(color, head, tail) ;
delay(1000) ;
}
//>
lightbounce.ino
#include <SPI.h>
#include <Adafruit_DotStar.h>
#define NUMPIXELS 30
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, DOTSTAR_BRG) ;
void bounceBetween(uint32_t color, uint16_t start, uint16_t finish, uint16_t len){
int path_length = finish-start ;
// Get light snake moving forward down the line.
for (int i=0 ; i < path_length ; i++){
// Populate the snake
for (int j=0 ; j < len ; j++){
if ((j+i+start) <= finish){
strip.setPixelColor(i+j+start, color) ;
strip.show() ;
}
}
// Write the end of the snake to be "off"
if ( (i+start) <= (finish-len) ){
strip.setPixelColor(i+start, 0) ;
delay(50) ;
}
}
// Get the light snake moving backwards.
for (int i=0 ; (-1)*i < path_length ; i--){
// Populate the snake
for (int j=0 ; (-1)*j < len ; j--){
if ((i+j+finish) >= start){
strip.setPixelColor(i+j+finish, color) ;
strip.show() ;
}
}
// Write the end of the snake to be "off"
if ( (i+finish) >= (len+start) ){
strip.setPixelColor(i+finish, 0) ;
delay(50) ;
}
}
}
uint32_t randColor(){
uint8_t red = random(0,255) ;
uint8_t blue = random(0,255) ;
uint8_t green = random(0,255) ;
uint32_t color = 0x000000 ; //GRB
color = color | (green << 16) ;
color = color | (red << 8) ;
color = color | blue ;
return color ;
}
void setup() {
strip.begin() ;
strip.show() ;
}
void loop() {
uint32_t color = randColor() ;
bounceBetween(color, 2, 12, 4) ;
}
//>