blob: 3bf21e2c8d0c14a7161ab2a2a1254c9e31ce3236 [file] [log] [blame]
Gordon Drogondda33052012-12-11 20:59:52 +00001/*
2 * okLed:
3 * Make the OK LED on the Pi Pulsate...
4 * Copyright (c) 2012 gordon Henderson, but please Share and Enjoy!
5 *
6 * Originally posted to the Raspberry Pi forums:
7 * http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581
8 *
9 * Compile this and store it somewhere, then kick it off at boot time
10 * e.g. by putting it in /etc/rc.local and running it in the
11 * background &
12 *
13 */
14
15#include <stdio.h>
16#include <errno.h>
17#include <string.h>
18#include <fcntl.h>
19#include <unistd.h>
20
21#include <wiringPi.h>
22#include <softPwm.h>
23
24#define OK_LED 16
25
26int main ()
27{
28 int fd, i ;
29
30 if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0)
31 {
32 fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ;
33 return 1 ;
34 }
35
36 write (fd, "none\n", 5) ;
37 close (fd) ;
38
39 if (wiringPiSetupGpio () < 0)
40 {
41 fprintf (stderr, "Unable to setup GPIO: %s\n", strerror (errno)) ;
42 return 1 ;
43 }
44
45 softPwmCreate (OK_LED, 0, 100) ;
46
47 for (;;)
48 {
49 for (i = 0 ; i <= 100 ; ++i)
50 {
51 softPwmWrite (OK_LED, i) ;
52 delay (10) ;
53 }
54 delay (50) ;
55
56 for (i = 100 ; i >= 0 ; --i)
57 {
58 softPwmWrite (OK_LED, i) ;
59 delay (10) ;
60 }
61 delay (10) ;
62 }
63
64 return 0 ;
65}