blob: 930f266b5c4a387870bd81982382f0cafa95b1a7 [file] [log] [blame]
Gordon Drogondda33052012-12-11 20:59:52 +00001/*
Gordon Henderson3fbc5642013-03-24 20:04:07 +00002 * okLed.c:
Gordon Drogondda33052012-12-11 20:59:52 +00003 * Make the OK LED on the Pi Pulsate...
Gordon Drogondda33052012-12-11 20:59:52 +00004 *
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 *
Gordon Henderson3fbc5642013-03-24 20:04:07 +000012 * 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 ***********************************************************************
Gordon Drogondda33052012-12-11 20:59:52 +000030 */
31
32#include <stdio.h>
33#include <errno.h>
34#include <string.h>
35#include <fcntl.h>
36#include <unistd.h>
Gordon Henderson3fbc5642013-03-24 20:04:07 +000037#include <math.h>
Gordon Drogondda33052012-12-11 20:59:52 +000038
39#include <wiringPi.h>
40#include <softPwm.h>
41
Phil Howard26c7fe32016-02-27 16:03:10 +000042// The OK/Act LED is connected to BCM_GPIO pin 16
43
Gordon Drogondda33052012-12-11 20:59:52 +000044#define OK_LED 16
45
46int main ()
47{
48 int fd, i ;
49
Phil Howard26c7fe32016-02-27 16:03:10 +000050 wiringPiSetupGpio () ;
51
52// Change the trigger on the OK/Act LED to "none"
53
Gordon Drogondda33052012-12-11 20:59:52 +000054 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 }
Gordon Drogondda33052012-12-11 20:59:52 +000059 write (fd, "none\n", 5) ;
60 close (fd) ;
61
Gordon Drogondda33052012-12-11 20:59:52 +000062 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}