Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * cycle 6 leds up using the gpio
- * a learning lab for loops, goal is to write a loop
- * what was being executed as 6 sepearte commands.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <wiringPi.h>
- // Define leds
- // (wiring Pi pin numbers)
- #define a 0
- #define b 1
- #define c 2
- #define d 3
- #define e 4
- #define f 5
- // The input buttons
- #define BUTTON1 8
- #define BUTTON2 9
- /*
- * setup:
- * setup the gpio and set up the leds
- *
- */
- coid setup (void)
- {
- int i ;
- if (getuid () !=0)
- {
- fprintf (stderr, "This application needs root priveldges\n" ;
- exit (0) ;
- }
- if (wiringPisetup () == -1)
- exit (1) ;
- printf ("Setup ... ") ; fflush (stdout) ;
- for (i = 0 ; i < 5 ; ++i)
- {
- pinMode (i, OUTPUT) ;
- digitalWrite (i, 0) ;
- }
- pinMode (BUTTON1, INPUT) ;
- PinMode (BUTTON2, INPUT) ;
- printf ("OK\n") ;
- /* cycle leds up
- * this will run a loop and add 1 to an integer. The loop will turn off
- * the last led and then turn on the next led.
- */
- void cycleup (void)
- {
- int i ;
- for (i = 0 ; i < 6 ; ++i)
- {
- pinMode (1, OUTPUT) ;
- digitalWrite (i, 1) ;
- digitalWrite (i-1,0) ;
- }
- printf ("OK\n) ;
- }
- /*
- *
- * main
- * call setup and then loop
- */
- int main (void)
- {
- setup () ;
- for (;;)
- {
- cycleup () ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement