No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

119 líneas
2.9 KiB

  1. /*
  2. * piGlow.c:
  3. * Easy access to the Pimoroni PiGlow board.
  4. *
  5. * Copyright (c) 2013 Gordon Henderson.
  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. */
  24. #include <wiringPi.h>
  25. #include <sn3218.h>
  26. #include "piGlow.h"
  27. #define PIGLOW_BASE 577
  28. static int leg0 [6] = { 6, 7, 8, 5, 4, 9 } ;
  29. static int leg1 [6] = { 17, 16, 15, 13, 11, 10 } ;
  30. static int leg2 [6] = { 0, 1, 2, 3, 14, 12 } ;
  31. /*
  32. * piGlow1:
  33. * Light up an individual LED
  34. *********************************************************************************
  35. */
  36. void piGlow1 (const int leg, const int ring, const int intensity)
  37. {
  38. int *legLeds ;
  39. if ((leg < 0) || (leg > 2)) return ;
  40. if ((ring < 0) || (ring > 5)) return ;
  41. /**/ if (leg == 0)
  42. legLeds = leg0 ;
  43. else if (leg == 1)
  44. legLeds = leg1 ;
  45. else
  46. legLeds = leg2 ;
  47. analogWrite (PIGLOW_BASE + legLeds [ring], intensity) ;
  48. }
  49. /*
  50. * piGlowLeg:
  51. * Light up all 6 LEDs on a leg
  52. *********************************************************************************
  53. */
  54. void piGlowLeg (const int leg, const int intensity)
  55. {
  56. int i ;
  57. int *legLeds ;
  58. if ((leg < 0) || (leg > 2))
  59. return ;
  60. /**/ if (leg == 0)
  61. legLeds = leg0 ;
  62. else if (leg == 1)
  63. legLeds = leg1 ;
  64. else
  65. legLeds = leg2 ;
  66. for (i = 0 ; i < 6 ; ++i)
  67. analogWrite (PIGLOW_BASE + legLeds [i], intensity) ;
  68. }
  69. /*
  70. * piGlowRing:
  71. * Light up 3 LEDs in a ring. Ring 0 is the outermost, 5 the innermost
  72. *********************************************************************************
  73. */
  74. void piGlowRing (const int ring, const int intensity)
  75. {
  76. if ((ring < 0) || (ring > 5))
  77. return ;
  78. analogWrite (PIGLOW_BASE + leg0 [ring], intensity) ;
  79. analogWrite (PIGLOW_BASE + leg1 [ring], intensity) ;
  80. analogWrite (PIGLOW_BASE + leg2 [ring], intensity) ;
  81. }
  82. /*
  83. * piGlowSetup:
  84. * Initialise the board & remember the pins we're using
  85. *********************************************************************************
  86. */
  87. void piGlowSetup (int clear)
  88. {
  89. sn3218Setup (PIGLOW_BASE) ;
  90. if (clear)
  91. {
  92. piGlowLeg (0, 0) ;
  93. piGlowLeg (1, 0) ;
  94. piGlowLeg (2, 0) ;
  95. }
  96. }