Skip to content

Instantly share code, notes, and snippets.

@willhooi
Last active January 29, 2018 04:26
Show Gist options
  • Save willhooi/2b91cd875ddd72ce0d7b81ec85af2bc8 to your computer and use it in GitHub Desktop.
Save willhooi/2b91cd875ddd72ce0d7b81ec85af2bc8 to your computer and use it in GitHub Desktop.
/* Cloud Lamp Programming Workshop
* Contributed by William Hooi/OneMaker Group Pte Ltd
* Based on examples provided by Adafruit NeoPixel tutorial
*
*/
#include <Adafruit_NeoPixel.h>
#define PIN 6 //define pin number
// 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(60, PIN, NEO_GRB + NEO_KHZ800);
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t magenta = strip.Color(255, 0, 255);
uint32_t yellow = strip.Color(255, 255, 0);
uint32_t cyan = strip.Color(0, 255, 255);
uint32_t none = strip.Color(0, 0, 0);
void setup() {
strip.begin ();
strip.Color(255,0,0);
}
void loop()
{
chase (red);
reverse (red);
chase (blue);
reverse (blue);
chase (green);
reverse (green);
chase (yellow);
reverse (yellow);
chase (cyan);
reverse (cyan);
chase (magenta);
reverse (magenta);
}
void chase (uint32_t c) {
for (int i=0; i<30; i++){
strip.setPixelColor(i, c);
strip.show();
strip.setPixelColor(i,0);
delay (25);
}
}
void reverse (uint32_t d) {
for (int i=30; i>0; i--){
strip.setPixelColor(i, d);
strip.show();
strip.setPixelColor(i,0);
delay (25);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment