chiark / gitweb /
Fixed the requirement for -lm
[wiringPi.git] / examples / pwm.c
index 09b4ae0d6c2bfe9455464f7775cf94c14fd1dc53..816c8322e357db2f56458a1bd4689aa61f75c64f 100644 (file)
@@ -1,69 +1,58 @@
-
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
+/*
+ * pwm.c:
+ *     This tests the hardware PWM channel.
+ *
+ * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
+ ***********************************************************************
+ * This file is part of wiringPi:
+ *     https://projects.drogon.net/raspberry-pi/wiringpi/
+ *
+ *    wiringPi is free software: you can redistribute it and/or modify
+ *    it under the terms of the GNU Lesser General Public License as published by
+ *    the Free Software Foundation, either version 3 of the License, or
+ *    (at your option) any later version.
+ *
+ *    wiringPi is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public License
+ *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.
+ ***********************************************************************
+ */
 
 #include <wiringPi.h>
-#include <softPwm.h>
-
-#define RANGE          100
-#define        NUM_LEDS         12
-
-int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 } ;
 
-int values [NUM_LEDS] = { 0, 17, 32, 50, 67, 85, 100, 85, 67, 50, 32, 17 } ;
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
 
-int main ()
+int main (void)
 {
-  int i, j ;
-  char buf [80] ;
+  int bright ;
 
-  if (wiringPiSetup () == -1)
-  {
-    fprintf (stdout, "oops: %s\n", strerror (errno)) ;
-    return 1 ;
-  }
-
-  for (i = 0 ; i < NUM_LEDS ; ++i)
-  {
-    softPwmCreate (ledMap [i], 0, RANGE) ;
-    printf ("%3d, %3d, %3d\n", i, ledMap [i], values [i]) ;
-  }
+  printf ("Raspberry Pi wiringPi PWM test program\n") ;
 
-  fgets (buf, 80, stdin) ;
+  if (wiringPiSetup () == -1)
+    exit (1) ;
 
-// Bring all up one by one:
+  pinMode (1, PWM_OUTPUT) ;
 
-  for (i = 0 ; i < NUM_LEDS ; ++i)
-    for (j = 0 ; j <= 100 ; ++j)
+  for (;;)
+  {
+    for (bright = 0 ; bright < 1024 ; ++bright)
     {
-      softPwmWrite (ledMap [i], j) ;
-      delay (10) ;
+      pwmWrite (1, bright) ;
+      delay (1) ;
     }
 
-  fgets (buf, 80, stdin) ;
-
-// Down fast
-
-  for (i = 100 ; i > 0 ; --i)
-  {
-    for (j = 0 ; j < NUM_LEDS ; ++j)
-      softPwmWrite (ledMap [j], i) ;
-    delay (10) ;
+    for (bright = 1023 ; bright >= 0 ; --bright)
+    {
+      pwmWrite (1, bright) ;
+      delay (1) ;
+    }
   }
 
-  fgets (buf, 80, stdin) ;
-
-  for (;;)
-  {
-    for (i = 0 ; i < NUM_LEDS ; ++i)
-      softPwmWrite (ledMap [i], values [i]) ;
-
-    delay (50) ;
-
-    i = values [0] ;
-    for (j = 0 ; j < NUM_LEDS - 1 ; ++j)
-      values [j] = values [j + 1] ;
-    values [NUM_LEDS - 1] = i ;
-  }
+  return 0 ;
 }