void piGlowSetup (int clear) { sn3218Setup (PIGLOW_BASE) ; if (clear) { piGlowLeg (0, 0) ; piGlowLeg (1, 0) ; piGlowLeg (2, 0) ; } }
static void pulseLeg (int leg) { int i ; for (i = 0 ; i < 140 ; ++i) { piGlowLeg (leg, i) ; delay (1) ; } delay (10) ; for (i = 140 ; i >= 0 ; --i) { piGlowLeg (leg, i) ; delay (1) ; } }
int main (void) { int i ; int step, ring, leg ; // Always initialise wiringPi: // Use the Sys method if you don't need to run as root wiringPiSetupSys () ; // Initialise the piGlow devLib with our chosen pin base piGlowSetup (1) ; // LEDs, one at a time printf ("LEDs, one at a time\n") ; for (; !keypressed () ;) for (leg = 0 ; leg < 3 ; ++leg) { for (ring = 0 ; ring < 6 ; ++ring) { pulseLed (leg, ring) ; if (keypressed ()) break ; } if (keypressed ()) break ; } clearKeypressed () ; // Rings, one at a time printf ("Rings, one at a time\n") ; for (; !keypressed () ;) for (ring = 0 ; ring < 6 ; ++ring) { pulseRing (ring) ; if (keypressed ()) break ; } clearKeypressed () ; // Legs, one at a time printf ("Legs, one at a time\n") ; for (; !keypressed () ;) for (leg = 0 ; leg < 3 ; ++leg) { pulseLeg (leg) ; if (keypressed ()) break ; } clearKeypressed () ; delay (1000) ; // Sequence - alternating rings, legs and random printf ("Sequence now\n") ; for (; !keypressed () ;) { for (i = 0 ; i < 20 ; ++i) for (step = 0 ; step < LEG_STEPS ; ++step) { for (leg = 0 ; leg < 3 ; ++leg) piGlowLeg (leg, legSequence [step * 3 + leg]) ; delay (80) ; } for (i = 0 ; i < 10 ; ++i) for (step = 0 ; step < RING_STEPS ; ++step) { for (ring = 0 ; ring < 6 ; ++ring) piGlowRing (ring, ringSequence [step * 6 + ring]) ; delay (80) ; } for (i = 0 ; i < 1000 ; ++i) { leg = random () % 3 ; ring = random () % 6 ; piGlow1 (leg, ring, random () % 256) ; delay (5) ; piGlow1 (leg, ring, 0) ; } } return 0 ; }
int main (int argc, char *argv []) { int percent ; int ring, leg ; // Always initialise wiringPi: // Use the Sys method if you don't need to run as root wiringPiSetupSys () ; // Initialise the piGlow devLib piGlowSetup (FALSE) ; if (argc == 1) failUsage () ; if ((argc == 2) && (strcasecmp (argv [1], "off") == 0)) { for (leg = 0 ; leg < 3 ; ++leg) piGlowLeg (leg, 0) ; return 0 ; } if (argc == 3) { percent = getPercent (argv [2]) ; /**/ if (strcasecmp (argv [1], "red") == 0) piGlowRing (PIGLOW_RED, percent) ; else if (strcasecmp (argv [1], "yellow") == 0) piGlowRing (PIGLOW_YELLOW, percent) ; else if (strcasecmp (argv [1], "orange") == 0) piGlowRing (PIGLOW_ORANGE, percent) ; else if (strcasecmp (argv [1], "green") == 0) piGlowRing (PIGLOW_GREEN, percent) ; else if (strcasecmp (argv [1], "blue") == 0) piGlowRing (PIGLOW_BLUE, percent) ; else if (strcasecmp (argv [1], "white") == 0) piGlowRing (PIGLOW_WHITE, percent) ; else if (strcasecmp (argv [1], "all") == 0) for (ring = 0 ; ring < 6 ; ++ring) piGlowRing (ring, percent) ; else { fprintf (stderr, "piglow: invalid colour\n") ; exit (EXIT_FAILURE) ; } return 0 ; } if (argc == 4) { /**/ if (strcasecmp (argv [1], "leg") == 0) { leg = atoi (argv [2]) ; if ((leg < 0) || (leg > 2)) { fprintf (stderr, "piglow: leg value out of range\n") ; exit (EXIT_FAILURE) ; } percent = getPercent (argv [3]) ; piGlowLeg (leg, percent) ; } else if (strcasecmp (argv [1], "ring") == 0) { ring = atoi (argv [2]) ; if ((ring < 0) || (ring > 5)) { fprintf (stderr, "piglow: ring value out of range\n") ; exit (EXIT_FAILURE) ; } percent = getPercent (argv [3]) ; piGlowRing (ring, percent) ; } return 0 ; } if (argc == 5) { if (strcasecmp (argv [1], "led") != 0) failUsage () ; leg = atoi (argv [2]) ; if ((leg < 0) || (leg > 2)) { fprintf (stderr, "piglow: leg value out of range\n") ; exit (EXIT_FAILURE) ; } ring = atoi (argv [3]) ; if ((ring < 0) || (ring > 5)) { fprintf (stderr, "piglow: ring value out of range\n") ; exit (EXIT_FAILURE) ; } percent = getPercent (argv [4]) ; piGlow1 (leg, ring, percent) ; return 0 ; } failUsage () ; return 0 ; }