Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

8 роки тому
8 роки тому
8 роки тому
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * softPwm.c:
  3. * Test of the software PWM driver. Needs 8 LEDs connected
  4. * to the Pi - e.g. Ladder board.
  5. *
  6. * Copyright (c) 2012-2013 Gordon Henderson.
  7. ***********************************************************************
  8. * This file is part of wiringPi:
  9. * https://github.com/WiringPi/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 8
  32. int ledMap [NUM_LEDS] = { 0, 1, 2, 3, 4, 5, 6, 7 } ;
  33. int values [NUM_LEDS] = { 0, 25, 50, 75, 100, 75, 50, 25 } ;
  34. int main ()
  35. {
  36. int i, j ;
  37. char buf [80] ;
  38. wiringPiSetup () ;
  39. for (i = 0 ; i < NUM_LEDS ; ++i)
  40. {
  41. softPwmCreate (ledMap [i], 0, RANGE) ;
  42. printf ("%3d, %3d, %3d\n", i, ledMap [i], values [i]) ;
  43. }
  44. fgets (buf, 80, stdin) ;
  45. // Bring all up one by one:
  46. for (i = 0 ; i < NUM_LEDS ; ++i)
  47. for (j = 0 ; j <= 100 ; ++j)
  48. {
  49. softPwmWrite (ledMap [i], j) ;
  50. delay (10) ;
  51. }
  52. fgets (buf, 80, stdin) ;
  53. // All Down
  54. for (i = 100 ; i > 0 ; --i)
  55. {
  56. for (j = 0 ; j < NUM_LEDS ; ++j)
  57. softPwmWrite (ledMap [j], i) ;
  58. delay (10) ;
  59. }
  60. fgets (buf, 80, stdin) ;
  61. for (;;)
  62. {
  63. for (i = 0 ; i < NUM_LEDS ; ++i)
  64. softPwmWrite (ledMap [i], values [i]) ;
  65. delay (50) ;
  66. i = values [0] ;
  67. for (j = 0 ; j < NUM_LEDS - 1 ; ++j)
  68. values [j] = values [j + 1] ;
  69. values [NUM_LEDS - 1] = i ;
  70. }
  71. }