25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

94 satır
2.3 KiB

  1. /*
  2. * pwm.c:
  3. * Test of the software PWM driver. Needs 12 LEDs connected
  4. * to the Pi.
  5. *
  6. * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
  7. ***********************************************************************
  8. * This file is part of wiringPi:
  9. * https://projects.drogon.net/raspberry-pi/wiringpi/
  10. *
  11. * wiringPi is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Lesser General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * wiringPi is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Lesser General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Lesser General Public License
  22. * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
  23. ***********************************************************************
  24. */
  25. #include <stdio.h>
  26. #include <errno.h>
  27. #include <string.h>
  28. #include <wiringPi.h>
  29. #include <softPwm.h>
  30. #define RANGE 100
  31. #define NUM_LEDS 12
  32. int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13 } ;
  33. int values [NUM_LEDS] = { 0, 17, 32, 50, 67, 85, 100, 85, 67, 50, 32, 17 } ;
  34. int main ()
  35. {
  36. int i, j ;
  37. char buf [80] ;
  38. if (wiringPiSetup () == -1)
  39. {
  40. fprintf (stdout, "oops: %s\n", strerror (errno)) ;
  41. return 1 ;
  42. }
  43. for (i = 0 ; i < NUM_LEDS ; ++i)
  44. {
  45. softPwmCreate (ledMap [i], 0, RANGE) ;
  46. printf ("%3d, %3d, %3d\n", i, ledMap [i], values [i]) ;
  47. }
  48. fgets (buf, 80, stdin) ;
  49. // Bring all up one by one:
  50. for (i = 0 ; i < NUM_LEDS ; ++i)
  51. for (j = 0 ; j <= 100 ; ++j)
  52. {
  53. softPwmWrite (ledMap [i], j) ;
  54. delay (10) ;
  55. }
  56. fgets (buf, 80, stdin) ;
  57. // Down fast
  58. for (i = 100 ; i > 0 ; --i)
  59. {
  60. for (j = 0 ; j < NUM_LEDS ; ++j)
  61. softPwmWrite (ledMap [j], i) ;
  62. delay (10) ;
  63. }
  64. fgets (buf, 80, stdin) ;
  65. for (;;)
  66. {
  67. for (i = 0 ; i < NUM_LEDS ; ++i)
  68. softPwmWrite (ledMap [i], values [i]) ;
  69. delay (50) ;
  70. i = values [0] ;
  71. for (j = 0 ; j < NUM_LEDS - 1 ; ++j)
  72. values [j] = values [j + 1] ;
  73. values [NUM_LEDS - 1] = i ;
  74. }
  75. }