mirror of
https://github.com/clockworkpi/WiringPi.git
synced 2025-12-13 08:18:48 +01:00
delayMicrosecondsHard re-written - again. Added a serialRead example program, and added in the okLed to the examples too. Updated/checked some of the GPIO/PWM code. Added in some experimental servo and tone generating code and and example or 2. Tweaks to the gpio command to correctly load the I2C modules too.
66 lines
1.2 KiB
C
66 lines
1.2 KiB
C
/*
|
|
* okLed:
|
|
* Make the OK LED on the Pi Pulsate...
|
|
* Copyright (c) 2012 gordon Henderson, but please Share and Enjoy!
|
|
*
|
|
* Originally posted to the Raspberry Pi forums:
|
|
* http://www.raspberrypi.org/phpBB3/viewtopic.php?p=162581#p162581
|
|
*
|
|
* Compile this and store it somewhere, then kick it off at boot time
|
|
* e.g. by putting it in /etc/rc.local and running it in the
|
|
* background &
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
|
|
#include <wiringPi.h>
|
|
#include <softPwm.h>
|
|
|
|
#define OK_LED 16
|
|
|
|
int main ()
|
|
{
|
|
int fd, i ;
|
|
|
|
if ((fd = open ("/sys/class/leds/led0/trigger", O_RDWR)) < 0)
|
|
{
|
|
fprintf (stderr, "Unable to change LED trigger: %s\n", strerror (errno)) ;
|
|
return 1 ;
|
|
}
|
|
|
|
write (fd, "none\n", 5) ;
|
|
close (fd) ;
|
|
|
|
if (wiringPiSetupGpio () < 0)
|
|
{
|
|
fprintf (stderr, "Unable to setup GPIO: %s\n", strerror (errno)) ;
|
|
return 1 ;
|
|
}
|
|
|
|
softPwmCreate (OK_LED, 0, 100) ;
|
|
|
|
for (;;)
|
|
{
|
|
for (i = 0 ; i <= 100 ; ++i)
|
|
{
|
|
softPwmWrite (OK_LED, i) ;
|
|
delay (10) ;
|
|
}
|
|
delay (50) ;
|
|
|
|
for (i = 100 ; i >= 0 ; --i)
|
|
{
|
|
softPwmWrite (OK_LED, i) ;
|
|
delay (10) ;
|
|
}
|
|
delay (10) ;
|
|
}
|
|
|
|
return 0 ;
|
|
}
|