PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.7KB

  1. /*
  2. CShiftPWM.h - Library for Arduino to PWM many outputs using shift registers
  3. Copyright (c) 2011-2012 Elco Jacobs, www.elcojacobs.com
  4. All right reserved.
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. */
  17. #ifndef CShiftPWM_h
  18. #define CShiftPWM_h
  19. #include <Arduino.h>
  20. class CShiftPWM{
  21. public:
  22. CShiftPWM(int timerInUse, bool noSPI, int latchPin, int dataPin, int clockPin);
  23. ~CShiftPWM();
  24. public:
  25. void Start(int ledFrequency, unsigned char max_Brightness);
  26. void SetAmountOfRegisters(unsigned char newAmount);
  27. void SetPinGrouping(int grouping);
  28. void PrintInterruptLoad(void);
  29. void OneByOneSlow(void);
  30. void OneByOneFast(void);
  31. void SetOne(int pin, unsigned char value);
  32. void SetAll(unsigned char value);
  33. void SetGroupOf2(int group, unsigned char v0, unsigned char v1, int offset = 0);
  34. void SetGroupOf3(int group, unsigned char v0, unsigned char v1, unsigned char v2, int offset = 0);
  35. void SetGroupOf4(int group, unsigned char v0, unsigned char v1, unsigned char v2, unsigned char v3, int offset = 0);
  36. void SetGroupOf5(int group, unsigned char v0, unsigned char v1, unsigned char v2, unsigned char v3, unsigned char v4, int offset = 0);
  37. void SetRGB(int led, unsigned char r,unsigned char g,unsigned char b, int offset = 0);
  38. void SetAllRGB(unsigned char r,unsigned char g,unsigned char b);
  39. void SetHSV(int led, unsigned int hue, unsigned int sat, unsigned int val, int offset = 0);
  40. void SetAllHSV(unsigned int hue, unsigned int sat, unsigned int val);
  41. private:
  42. void OneByOne_core(int delaytime);
  43. bool IsValidPin(int pin);
  44. void InitTimer1(void);
  45. #if defined(OCR3A)
  46. // Arduino Leonardo or Micro (32u4)
  47. void InitTimer3(void);
  48. #endif
  49. #if defined(OCR2A)
  50. // Normal Arduino (328)
  51. void InitTimer2(void);
  52. #endif
  53. bool LoadNotTooHigh(void);
  54. const int m_timer;
  55. const bool m_noSPI;
  56. const int m_latchPin;
  57. const int m_dataPin;
  58. const int m_clockPin;
  59. int m_prescaler;
  60. public:
  61. int m_ledFrequency;
  62. unsigned char m_maxBrightness;
  63. unsigned char m_amountOfRegisters;
  64. int m_amountOfOutputs;
  65. int m_pinGrouping;
  66. unsigned char * m_PWMValues;
  67. unsigned char m_counter;
  68. };
  69. #endif