p kj
/
LPC824-BlynkWeatherstation
Microduino
Fork of Io_moon by
Blynk_v0_3_7/Blynk/WidgetLED.h@0:740c1eb2df13, 2016-06-23 (annotated)
- Committer:
- lixianyu
- Date:
- Thu Jun 23 11:16:14 2016 +0000
- Revision:
- 0:740c1eb2df13
* AM2321?????????2s????i2c?????; * SimpleTimer??bug?????????????????????????; * Blynk??bug??????????????; * ?????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lixianyu | 0:740c1eb2df13 | 1 | /** |
lixianyu | 0:740c1eb2df13 | 2 | * @file WidgetLED.h |
lixianyu | 0:740c1eb2df13 | 3 | * @author Volodymyr Shymanskyy |
lixianyu | 0:740c1eb2df13 | 4 | * @license This project is released under the MIT License (MIT) |
lixianyu | 0:740c1eb2df13 | 5 | * @copyright Copyright (c) 2015 Volodymyr Shymanskyy |
lixianyu | 0:740c1eb2df13 | 6 | * @date Apr 2015 |
lixianyu | 0:740c1eb2df13 | 7 | * @brief |
lixianyu | 0:740c1eb2df13 | 8 | */ |
lixianyu | 0:740c1eb2df13 | 9 | |
lixianyu | 0:740c1eb2df13 | 10 | #ifndef WidgetLED_h |
lixianyu | 0:740c1eb2df13 | 11 | #define WidgetLED_h |
lixianyu | 0:740c1eb2df13 | 12 | |
lixianyu | 0:740c1eb2df13 | 13 | #include <Blynk/BlynkApi.h> |
lixianyu | 0:740c1eb2df13 | 14 | |
lixianyu | 0:740c1eb2df13 | 15 | class WidgetLED |
lixianyu | 0:740c1eb2df13 | 16 | { |
lixianyu | 0:740c1eb2df13 | 17 | public: |
lixianyu | 0:740c1eb2df13 | 18 | WidgetLED(uint8_t pin) : mPin(pin) {} |
lixianyu | 0:740c1eb2df13 | 19 | void setVPin(int vPin) { mPin = vPin; } |
lixianyu | 0:740c1eb2df13 | 20 | |
lixianyu | 0:740c1eb2df13 | 21 | #ifdef BLYNK_EXPERIMENTAL |
lixianyu | 0:740c1eb2df13 | 22 | |
lixianyu | 0:740c1eb2df13 | 23 | void setRGB(uint8_t r, uint8_t g, uint8_t b) { |
lixianyu | 0:740c1eb2df13 | 24 | char mem[64] = ""; |
lixianyu | 0:740c1eb2df13 | 25 | BlynkParam cmd(mem, 0, sizeof(mem)); |
lixianyu | 0:740c1eb2df13 | 26 | cmd.add("rgb"); |
lixianyu | 0:740c1eb2df13 | 27 | cmd.add(r); |
lixianyu | 0:740c1eb2df13 | 28 | cmd.add(g); |
lixianyu | 0:740c1eb2df13 | 29 | cmd.add(b); |
lixianyu | 0:740c1eb2df13 | 30 | Blynk.virtualWrite(mPin, cmd); |
lixianyu | 0:740c1eb2df13 | 31 | } |
lixianyu | 0:740c1eb2df13 | 32 | |
lixianyu | 0:740c1eb2df13 | 33 | void setHSV(uint8_t h, uint8_t s, uint8_t v) { |
lixianyu | 0:740c1eb2df13 | 34 | char mem[64] = ""; |
lixianyu | 0:740c1eb2df13 | 35 | BlynkParam cmd(mem, 0, sizeof(mem)); |
lixianyu | 0:740c1eb2df13 | 36 | cmd.add("hsv"); |
lixianyu | 0:740c1eb2df13 | 37 | cmd.add(h); |
lixianyu | 0:740c1eb2df13 | 38 | cmd.add(s); |
lixianyu | 0:740c1eb2df13 | 39 | cmd.add(v); |
lixianyu | 0:740c1eb2df13 | 40 | Blynk.virtualWrite(mPin, cmd); |
lixianyu | 0:740c1eb2df13 | 41 | } |
lixianyu | 0:740c1eb2df13 | 42 | |
lixianyu | 0:740c1eb2df13 | 43 | #endif |
lixianyu | 0:740c1eb2df13 | 44 | |
lixianyu | 0:740c1eb2df13 | 45 | uint8_t getValue() const { |
lixianyu | 0:740c1eb2df13 | 46 | return mValue; |
lixianyu | 0:740c1eb2df13 | 47 | } |
lixianyu | 0:740c1eb2df13 | 48 | |
lixianyu | 0:740c1eb2df13 | 49 | void setValue(uint8_t value) { |
lixianyu | 0:740c1eb2df13 | 50 | mValue = value; |
lixianyu | 0:740c1eb2df13 | 51 | Blynk.virtualWrite(mPin, value); |
lixianyu | 0:740c1eb2df13 | 52 | } |
lixianyu | 0:740c1eb2df13 | 53 | |
lixianyu | 0:740c1eb2df13 | 54 | void on() { |
lixianyu | 0:740c1eb2df13 | 55 | setValue(255); |
lixianyu | 0:740c1eb2df13 | 56 | } |
lixianyu | 0:740c1eb2df13 | 57 | |
lixianyu | 0:740c1eb2df13 | 58 | void off() { |
lixianyu | 0:740c1eb2df13 | 59 | setValue(0); |
lixianyu | 0:740c1eb2df13 | 60 | } |
lixianyu | 0:740c1eb2df13 | 61 | |
lixianyu | 0:740c1eb2df13 | 62 | private: |
lixianyu | 0:740c1eb2df13 | 63 | uint8_t mPin; |
lixianyu | 0:740c1eb2df13 | 64 | uint8_t mValue; |
lixianyu | 0:740c1eb2df13 | 65 | }; |
lixianyu | 0:740c1eb2df13 | 66 | |
lixianyu | 0:740c1eb2df13 | 67 | #endif |
lixianyu | 0:740c1eb2df13 | 68 |