chiark / gitweb /
Fixed delayMicroseconds for more than 1 second.
[wiringPi.git] / examples / okLed.c
1 /*
2  * okLed.c:
3  *      Make the OK LED on the Pi Pulsate...
4  *
5  * Originally posted to the Raspberry Pi forums:
6  *  http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581
7  *
8  * Compile this and store it somewhere, then kick it off at boot time
9  *    e.g. by putting it in /etc/rc.local and running it in the
10  *    background &
11  *
12  * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
13  ***********************************************************************
14  * This file is part of wiringPi:
15  *      https://projects.drogon.net/raspberry-pi/wiringpi/
16  *
17  *    wiringPi is free software: you can redistribute it and/or modify
18  *    it under the terms of the GNU Lesser General Public License as published by
19  *    the Free Software Foundation, either version 3 of the License, or
20  *    (at your option) any later version.
21  *
22  *    wiringPi is distributed in the hope that it will be useful,
23  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
24  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  *    GNU Lesser General Public License for more details.
26  *
27  *    You should have received a copy of the GNU Lesser General Public License
28  *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
29  ***********************************************************************
30  */
31
32 #include <stdio.h>
33 #include <errno.h>
34 #include <string.h>
35 #include <fcntl.h>
36 #include <unistd.h>
37 #include <math.h>
38
39 #include <wiringPi.h>
40 #include <softPwm.h>
41
42 // The OK/Act LED is connected to BCM_GPIO pin 16
43
44 #define OK_LED  16
45
46 int main ()
47 {
48   int fd, i ;
49
50   wiringPiSetupGpio () ;
51
52 // Change the trigger on the OK/Act LED to "none"
53
54   if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0)
55   {
56     fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ;
57     return 1 ;
58   }
59   write (fd, "none\n", 5) ;
60   close (fd) ;
61
62   softPwmCreate (OK_LED, 0, 100) ;
63
64   for (;;)
65   {
66     for (i = 0 ; i <= 100 ; ++i)
67     {
68       softPwmWrite (OK_LED, i) ;
69       delay (10) ;
70     }
71     delay (50) ;
72
73     for (i = 100 ; i >= 0 ; --i)
74     {
75       softPwmWrite (OK_LED, i) ;
76       delay (10) ;
77     }
78     delay (10) ;
79   }
80
81   return 0 ;
82 }