BrickUp API Service for Docker version.

Grove_LED_Bar.h 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. LED bar library V2.0
  3. 2010 Copyright (c) Seeed Technology Inc. All right reserved.
  4. Original Author: LG
  5. Modify: Loovee, 2014-2-26
  6. User can choose which Io to be used.
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. This library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. /*
  20. Modify: Long, 2015-01-07
  21. User can change the brightness level for each LED segment
  22. Rename constant to avoid name conflict
  23. */
  24. #ifndef Grove_LED_Bar_H
  25. #define Grove_LED_Bar_H
  26. #include <Arduino.h>
  27. // Avoid name conflict
  28. #define GLB_CMDMODE 0x00 // Work on 8-bit mode
  29. #define GLB_ON 0xff // 8-bit 1 data
  30. #define GLB_OFF 0x00 // 8-bit 0 data
  31. class Grove_LED_Bar
  32. {
  33. private:
  34. unsigned int __pinClock; // Clock pin
  35. unsigned int __pinData; // Data pin
  36. bool __greenToRed; // Orientation (0 = red to green, 1 = green to red)
  37. unsigned char __state[10];// Led state, brightness for each LED
  38. void sendData(unsigned int data); // Send a word to led bar
  39. void latchData(void); // Load data into the latch register
  40. void setData(unsigned char bits[]);//Set data array
  41. public:
  42. Grove_LED_Bar(unsigned char pinClock, unsigned char pinData, bool greenToRed); // Initialize
  43. void begin(){pinMode(__pinClock, OUTPUT); pinMode(__pinData, OUTPUT);}
  44. void setGreenToRed(bool greenToRed); // (Re)set orientation
  45. void setLevel(float level); // Set level, range from 0 to 10
  46. void setLed(unsigned char led, float brightness);// Set brightness for a single led, range from 0 to 1
  47. void toggleLed(unsigned char led); // Toggle a single led
  48. void setBits(unsigned int bits); // Toggle leds to match given bits
  49. unsigned int const getBits(); // Get the current state
  50. };
  51. #endif