blob: 816c8322e357db2f56458a1bd4689aa61f75c64f [file] [log] [blame]
Gordon Henderson3fbc5642013-03-24 20:04:07 +00001/*
2 * pwm.c:
Phil Howard26c7fe32016-02-27 16:03:10 +00003 * This tests the hardware PWM channel.
Gordon Henderson3fbc5642013-03-24 20:04:07 +00004 *
5 * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
6 ***********************************************************************
7 * This file is part of wiringPi:
8 * https://projects.drogon.net/raspberry-pi/wiringpi/
9 *
10 * wiringPi is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * wiringPi is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
22 ***********************************************************************
23 */
Gordon Hendersonae40bda2012-08-28 18:37:54 +010024
Gordon Hendersonae40bda2012-08-28 18:37:54 +010025#include <wiringPi.h>
Gordon Hendersonae40bda2012-08-28 18:37:54 +010026
Phil Howard26c7fe32016-02-27 16:03:10 +000027#include <stdio.h>
28#include <stdlib.h>
29#include <stdint.h>
Gordon Hendersonae40bda2012-08-28 18:37:54 +010030
Phil Howard26c7fe32016-02-27 16:03:10 +000031int main (void)
Gordon Hendersonae40bda2012-08-28 18:37:54 +010032{
Phil Howard26c7fe32016-02-27 16:03:10 +000033 int bright ;
34
35 printf ("Raspberry Pi wiringPi PWM test program\n") ;
Gordon Hendersonae40bda2012-08-28 18:37:54 +010036
37 if (wiringPiSetup () == -1)
Phil Howard26c7fe32016-02-27 16:03:10 +000038 exit (1) ;
Gordon Hendersonae40bda2012-08-28 18:37:54 +010039
Phil Howard26c7fe32016-02-27 16:03:10 +000040 pinMode (1, PWM_OUTPUT) ;
Gordon Hendersonae40bda2012-08-28 18:37:54 +010041
42 for (;;)
43 {
Phil Howard26c7fe32016-02-27 16:03:10 +000044 for (bright = 0 ; bright < 1024 ; ++bright)
45 {
46 pwmWrite (1, bright) ;
47 delay (1) ;
48 }
Gordon Hendersonae40bda2012-08-28 18:37:54 +010049
Phil Howard26c7fe32016-02-27 16:03:10 +000050 for (bright = 1023 ; bright >= 0 ; --bright)
51 {
52 pwmWrite (1, bright) ;
53 delay (1) ;
54 }
Gordon Hendersonae40bda2012-08-28 18:37:54 +010055 }
Phil Howard26c7fe32016-02-27 16:03:10 +000056
57 return 0 ;
Gordon Hendersonae40bda2012-08-28 18:37:54 +010058}