elbear_arduino_bsp/libraries/NeoPixel/examples/simpleWithSerial/simpleWithSerial.ino

58 lines
1.2 KiB
C++

#include <NeoPixel.h>
#define PIN 2
#define NUMPIXELS 1
NeoPixel pixels(NUMPIXELS, PIN);
void setup() {
// init Serial and pin for led control
Serial.begin(9600);
pixels.begin();
Serial.println("pixels.begin");
delay(1000);
// clear pixels and show
pixels.clear();
pixels.show();
Serial.println("pixels.clear");
delay(1000);
}
void loop() {
// sequentially set a new pixel color and show it
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0xff, 0x00, 0x00));
pixels.show();
}
Serial.println("pixels.Color red");
delay(1000);
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0x00, 0xff, 0x00));
pixels.show();
}
Serial.println("pixels.Color green");
delay(1000);
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0x00, 0x00, 0xff));
pixels.show();
}
Serial.println("pixels.Color blue");
delay(1000);
for(int i=0; i<NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0xff, 0xff, 0xff));
pixels.show();
}
Serial.println("pixels.Color white");
delay(1000);
// clear leds
pixels.clear();
pixels.show();
Serial.println("pixels.clear");
delay(1000);
}