Created
October 25, 2018 14:19
-
-
Save pinglunliao/658f63ad458ce64b60ffc6734a8890d8 to your computer and use it in GitHub Desktop.
This file contains 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
#include <Adafruit_NeoPixel.h> | |
#define F_BTN_PIN 3 // forward button | |
#define B_BTN_PIN 4 // backward button | |
#define PIN 2 // input pin Neopixel is attached to | |
#define NUMPIXELS 24 // number of neopixels in Ring | |
#define HALF_NUMPIXELS 12 | |
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
int delayval = 50; // timing delay | |
int redColor = 255; | |
int dimRedColor = 64; | |
int fBtnState = 0; | |
int bBtnState = 0; | |
void setup() { | |
pixels.begin(); // Initializes the NeoPixel library. | |
Serial.begin(9600); | |
pinMode(F_BTN_PIN, INPUT); | |
pinMode(B_BTN_PIN, INPUT); | |
} | |
void loop() { | |
// read the state of the pushbutton value: | |
fBtnState = digitalRead(F_BTN_PIN); | |
bBtnState = digitalRead(B_BTN_PIN); | |
// check if the pushbutton is pressed. If it is, the buttonState is HIGH: | |
if (fBtnState == HIGH) { | |
// | |
// Light up each LED in clockwise direction | |
// | |
for(int i=0;i<NUMPIXELS;i++){ | |
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 | |
pixels.setPixelColor(i, pixels.Color(redColor, 0, 0)); // Moderately bright green color. | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
delay(delayval); // Delay for a period of time (in milliseconds). | |
} | |
for(int t = 0; t < 20; t++) { | |
for(int i=HALF_NUMPIXELS;i<NUMPIXELS;i+=2){ | |
pixels.setPixelColor(i, pixels.Color(dimRedColor, 0, 0)); // Moderately bright green color. | |
} | |
for(int i=HALF_NUMPIXELS+1;i<NUMPIXELS;i+=2){ | |
pixels.setPixelColor(i, pixels.Color(redColor, 0, 0)); // Moderately bright green color. | |
} | |
pixels.show(); | |
delay(delayval); | |
for(int i=HALF_NUMPIXELS+1;i<NUMPIXELS;i+=2){ | |
pixels.setPixelColor(i, pixels.Color(dimRedColor, 0, 0)); // Moderately bright green color. | |
} | |
for(int i=HALF_NUMPIXELS;i<NUMPIXELS;i+=2){ | |
pixels.setPixelColor(i, pixels.Color(redColor, 0, 0)); // Moderately bright green color. | |
} | |
pixels.show(); | |
delay(delayval); | |
} | |
for(int i=0;i<NUMPIXELS;i++){ | |
// turn off led | |
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Moderately bright green color. | |
pixels.show(); | |
delay(delayval); // Delay for a period of time (in milliseconds). | |
} | |
} else if (bBtnState == HIGH) { | |
// | |
// Light up each LED in counter-clockwise direction | |
// | |
for(int i=NUMPIXELS-1;i>=0;i--){ | |
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255 | |
pixels.setPixelColor(i, pixels.Color(redColor, 0, 0)); // Moderately bright green color. | |
pixels.show(); // This sends the updated pixel color to the hardware. | |
delay(delayval); // Delay for a period of time (in milliseconds). | |
} | |
for(int t = 0; t < 20; t++) { | |
for(int i=0; i <= HALF_NUMPIXELS;i+=2){ | |
pixels.setPixelColor(i, pixels.Color(dimRedColor, 0, 0)); // Moderately bright green color. | |
} | |
for(int i=1; i <= HALF_NUMPIXELS;i+=2){ | |
pixels.setPixelColor(i, pixels.Color(redColor, 0, 0)); // Moderately bright green color. | |
} | |
pixels.show(); | |
delay(delayval); | |
for(int i=1; i <= HALF_NUMPIXELS;i+=2){ | |
pixels.setPixelColor(i, pixels.Color(dimRedColor, 0, 0)); // Moderately bright green color. | |
} | |
for(int i=0; i <= HALF_NUMPIXELS;i+=2){ | |
pixels.setPixelColor(i, pixels.Color(redColor, 0, 0)); // Moderately bright green color. | |
} | |
pixels.show(); | |
delay(delayval); | |
} | |
for(int i=NUMPIXELS-1;i>=0;i--){ | |
// turn off led | |
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Moderately bright green color. | |
pixels.show(); | |
delay(delayval); // Delay for a period of time (in milliseconds). | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment