static void init_unicorn_hat(void) { int i; struct sigaction sa; numLEDs = 64; initHardware(); clearLEDBuffer(); setBrightness(DEFAULT_BRIGHTNESS); for (i = 0; i < 64; i++) { memset(&sa, 0, sizeof(sa)); sa.sa_handler = unicornd_exit; sigaction(i, &sa, NULL); } }
int main(int argc, char **argv) { int shader = 0; if (argc >= 3){ if(sscanf (argv[2], "%i", &anim_delay)!=1){ printf ("Error, delay must be an integer \n"); return 0; } } int newbrightness = 0; if (argc >= 4){ if(sscanf (argv[3], "%i", &newbrightness)!=1){ printf ("Error, brightness must be an integer \n"); return 0; }else{ setBrightness(newbrightness); } } if (argc == 2){ if(sscanf (argv[1], "%i", &newbrightness)==1){ setBrightness(newbrightness); shader = 1; } } int i; for (i = 0; i < 64; i++) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = unicorn_exit; sigaction(i, &sa, NULL); } setvbuf(stdout, NULL, _IONBF, 0); if(ws2811_init(&ledstring)) { return -1; } clearLEDBuffer(); if(argc < 2){ shader = 1; } if(shader){ run_shader(); }else{ read_png_file(argv[1]); while(1){ process_file(); if (height/8 == 1){ break; } } } unicorn_exit(0); return 0; }
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; }