void loop() { // Some example procedures showing how to display to the pixels colorWipe(Color(255, 0, 0), 50); colorWipe(Color(0, 255, 0), 50); colorWipe(Color(0, 0, 255), 50); rainbow(20); rainbowCycle(20); }
// Cycles through each LED pixel, testing each color along the way. void testColor(struct WS2812B_Strip *strip, const uint8_t red, const uint8_t green, const uint8_t blue, const uint32_t delayTime) { if (strip->inInterrupt == true) { return; } colorWipe(strip, color(red, green, blue), delayTime); return; }
void loop() { // Some example procedures showing how to display to the pixels: // Do not run more than 15 seconds of these, or the b/g tasks // will be blocked. // -------------------------------------------------------------- colorWipe(strip.Color(255, 0, 0), 50); // Red colorWipe(strip.Color(0, 255, 0), 50); // Green colorWipe(strip.Color(0, 0, 255), 50); // Blue colorWipe(strip.Color(0, 0, 0, 255), 50); // White whiteOverRainbow(20,75,5); pulseWhite(5); // fullWhite(); // delay(2000); rainbowFade2White(3,3,1); }
void showLed3AndHelloServo(int val){ Serial.println("led array was...."); Serial.println(val); Serial.println("ooooooooooooooooooo"); //strip.clear(); switch(val){ case 123://how colorWipe(strip.Color(255, 255, 255), 100); // white colorWipe(strip.Color(0, 0, 0), 100); // black colorWipe(strip.Color(255, 255, 255), 100); // white colorWipe(strip.Color(0, 0, 0), 100); // black colorWipe(strip.Color(255, 255, 255), 100); // white colorWipe(strip.Color(0, 0, 0), 100); // black //TODO Arduinoをリセット wdt_enable(WDTO_15MS); // turn on the WatchDog and don't stroke it. for(;;) { // do nothing and wait for the eventual... } break; case 1://サーボ準備 sv.attach(SERVO_PIN); Serial.println("servo attached...");//サーボの位置確認 break; case 2://サーボ回転 Serial.println(sv.read());//サーボの位置確認 moveServoShaft(0, 10); //delay(100);//TODO 不要 delay(1000); break; case 3://サーボ戻す Serial.println(sv.read());//サーボの位置確認 moveServoShaft(90, 10); //delay(100);//TODO 不要 delay(1000); break; case 4://サーボ終了 sv.detach(); break; case 0://クリア strip.clear(); break; case 555://白 case 5://白 colorWipe(strip.Color(255, 255, 255), 80); // white delay(3000); colorWipe(strip.Color(0, 0, 0), 100); // black break; case 666://紫 case 6://紫 colorWipe(strip.Color(105, 14, 102), 80); // purple delay(3000); colorWipe(strip.Color(0, 0, 0), 100); // black break; case 777://ピンク case 7://ピンク colorWipe(strip.Color(252, 18, 245), 80); // pink delay(3000); colorWipe(strip.Color(0, 0, 0), 100); // black break; case 888://レインボー? case 8://レインボー? rainbow(20); //rainbowCycle(80); break; case 999://黒 = 消す case 9://黒 = 消す colorWipe(strip.Color(0, 0, 0), 10); // black strip.clear(); break; case 100://予備 break; default: Serial.println("this is for servo"); colorWipe(strip.Color(0, 0, 0), 10); // black strip.clear(); break; } }
int main(int argc, char **argv) { // Catch all signals possible - it's vital we kill the DMA engine on process exit! uint8_t i; for (i = 0; i < 64; i++) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = unicorn_exit; sigaction(i, &sa, NULL); } // Get the input args if any int newbrightness = DEFAULT_BRIGHTNESS*100; if (argc == 2) { if(sscanf (argv[1], "%i", &newbrightness)!=1){ printf ("Error, brightness must be an integer \n"); return 0; } } else if (argc == 3) { if(sscanf (argv[1], "%i", &newbrightness)!=1){ printf ("Error, brightness must be an integer \n"); return 0; } if(sscanf (argv[2], "%i", &pulse_second) > 1){ printf ("Error, second pulsing must be an bool \n"); return 0; } } else if (argc == 4) { if(sscanf (argv[1], "%i", &newbrightness)!=1){ printf ("Error, brightness must be an integer \n"); return 0; } if(sscanf (argv[2], "%i", &pulse_second) > 1){ printf ("Error, second pulsing must be an bool \n"); return 0; } if(sscanf (argv[3], "%i", &rotate) > 1){ printf ("Error, rotate must be an bool \n"); return 0; } } // Don't buffer console output setvbuf(stdout, NULL, _IONBF, 0); // Set the number of pixels numLEDs = PIXEL_COLUMN*PIXEL_ROW; // Set the brightness setBrightness(newbrightness/100.0); // init WS2812 initHardware(); clearLEDBuffer(); // Create the matrix lookup map initMatrixMap(pixelMap,rotate); // Wipe through rgb for LED debug at start up colorWipe(Color(255,0,0),WIPE_DELAY); colorWipe(Color(0,255,0),WIPE_DELAY); colorWipe(Color(0,0,255),WIPE_DELAY); colorWipe(Color(0,0,0),WIPE_DELAY); while(1) { // The get time and set matrix loop (Arduino lagacy) loop(); // Wait a second before checking the time again usleep(1000*1000); } // Shouldn't get here but if we do, exit gracefully unicorn_exit(0); return 0; }
int main(int argc, char **argv) { // Check "Single Instance" int pid_file = open("/var/run/ws2812RPi.pid", O_CREAT | O_RDWR, 0666); int rc = flock(pid_file, LOCK_EX | LOCK_NB); if(rc) { if(EWOULDBLOCK == errno) { // another instance is running printf("Instance already running\n"); exit(EXIT_FAILURE); } } srand(time(NULL)); // seed the random number generator; should be done only once // Catch all signals possible - it's vital we kill the DMA engine on process exit! int i; for (i = 0; i < 64; i++) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = terminate; sigaction(i, &sa, NULL); } // Don't buffer console output setvbuf(stdout, NULL, _IONBF, 0); // How many LEDs? numLEDs = NUM_PIXELS; // How bright? (Recommend 0.2 for direct viewing @ 3.3V) setBrightness(DEFAULT_BRIGHTNESS); // Init PWM generator and clear LED buffer initHardware(); clearLEDBuffer(); // time_t t = time(NULL); // struct tm tm = *localtime(&t); // printf("Start: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); while(true) { // goto Twinkle_Test; rainbowCycle_wipe(5); // // tm = *localtime(&t); // // printf("rainbowCycle_wipe() Done: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); for (i = 0; i < loops; i++) { rainbowCycle_r(5); } // tm = *localtime(&t); // printf("rainbowCycle_f() Done: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); for (i = 0; i < loops; i++) { rainbowCycle(5); } // time_t t = time(NULL); // struct tm tm = *localtime(&t); // printf("rainbowCycle() Done: %d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); // RainFall(Color(0, 255, 0),5); int lastcolour; int randnum; for (i = 0; i < 10; i++) { RainLoop: randnum = rand() % 6; if (randnum == lastcolour) { goto RainLoop; } lastcolour = randnum; switch(randnum) { case 0: RainFall(Color(255, 0, 0),5,3); break; case 1: RainFall(Color(255, 128, 0),5,3); break; case 2: RainFall(Color(255, 255, 0),5,3); break; case 3: RainFall(Color(128, 255, 0),5,3); break; case 4: RainFall(Color(0, 255, 0),5,3); break; case 5: RainFall(Color(0, 0, 255),5,3); break; case 6: RainFall(Color(255, 0, 255),5,3); break; } } WipeColour0: randnum = rand() % 6; if (randnum == lastcolour) { goto WipeColour0; } lastcolour = randnum; switch(randnum) { case 0: colorWipe(Color(255, 0, 0),50); break; case 1: colorWipe(Color(255, 128, 0),50); break; case 2: colorWipe(Color(255, 255, 0),50); break; case 3: colorWipe(Color(128, 255, 0),50); break; case 4: colorWipe(Color(0, 255, 0),50); break; case 5: colorWipe(Color(0, 0, 255),50); break; case 6: colorWipe(Color(255, 0, 255),50); break; } sleep(5); for (i = 0; i < 5; i++) { WipeColour1: randnum = rand() % 6; if (randnum == lastcolour) { goto WipeColour1; } lastcolour = randnum; switch(randnum) { case 0: colorWipe_r(Color(255, 0, 0),50); break; case 1: colorWipe_r(Color(255, 128, 0),50); break; case 2: colorWipe_r(Color(255, 255, 0),50); break; case 3: colorWipe_r(Color(128, 255, 0),50); break; case 4: colorWipe_r(Color(0, 255, 0),50); break; case 5: colorWipe_r(Color(0, 0, 255),50); break; case 6: colorWipe_r(Color(255, 0, 255),50); break; } sleep(5); WipeColour2: randnum = rand() % 6; if (randnum == lastcolour) { goto WipeColour2; } lastcolour = randnum; switch(randnum) { case 0: colorWipe(Color(255, 0, 0),50); break; case 1: colorWipe(Color(255, 128, 0),50); break; case 2: colorWipe(Color(255, 255, 0),50); break; case 3: colorWipe(Color(128, 255, 0),50); break; case 4: colorWipe(Color(0, 255, 0),50); break; case 5: colorWipe(Color(0, 0, 255),50); break; case 6: colorWipe(Color(255, 0, 255),50); break; } sleep(5); } // Twinkle_Test: // RainFall(Color(0, 0, 0),5,3); // for (i=0; i < 600; i++) { // TwinkleColour2: // randnum = rand() % 3; // if (randnum == lastcolour) { // goto TwinkleColour2; // } // lastcolour = randnum; // switch(randnum) { // case 0: // Twinkle_T(Color(0, 0, 255)); // break; // case 1: // Twinkle_T(Color(255, 128, 0)); // break; // case 2: // Twinkle_T(Color(0, 255, 0)); // break; // case 3: // Twinkle_T(Color(0, 0, 0)); // break; // } // } Twinkle_Test: colorWipe(Color(0, 0, 0),50); usleep(500000); // for (i=0; i < 600; i++) { for (i=0; i < 600; i++) { Twinkle(); } Twinkle_Fade(); sleep(3); // colorWipe(Color(0, 0, 0),50); } // Exit cleanly, freeing memory and stopping the DMA & PWM engines // We trap all signals (including Ctrl+C), so even if you don't get here, it terminates correctly terminate(0); return 0; }
void NeoPixelEffects::colorYellow() { colorWipe(_strip->Color(127, 127, 0)); // Yellow }
void NeoPixelEffects::colorGreen() { colorWipe(_strip->Color(0, 127, 0)); // Blue }
void NeoPixelEffects::colorBlue() { colorWipe(_strip->Color(0, 0, 127)); // Blue }
void NeoPixelEffects::colorRed() { colorWipe(_strip->Color(127, 0, 0)); // Red }