blob: 9b3a170ca3200caedcac70f2d22d2310bacfcbd5 [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
42#define OK_LED 16
43
44int main ()
45{
46 int fd, i ;
47
48 if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0)
49 {
50 fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ;
51 return 1 ;
52 }
53
54 write (fd, "none\n", 5) ;
55 close (fd) ;
56
57 if (wiringPiSetupGpio () < 0)
58 {
59 fprintf (stderr, "Unable to setup GPIO: %s\n", strerror (errno)) ;
60 return 1 ;
61 }
62
63 softPwmCreate (OK_LED, 0, 100) ;
64
65 for (;;)
66 {
67 for (i = 0 ; i <= 100 ; ++i)
68 {
69 softPwmWrite (OK_LED, i) ;
70 delay (10) ;
71 }
72 delay (50) ;
73
74 for (i = 100 ; i >= 0 ; --i)
75 {
76 softPwmWrite (OK_LED, i) ;
77 delay (10) ;
78 }
79 delay (10) ;
80 }
81
82 return 0 ;
83}