-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBlinkM.h
120 lines (88 loc) · 3.03 KB
/
BlinkM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* BlinkM.h-- Arduino library to control BlinkM family products
* --------------
*
*
* Note: original version of this started as "BlinkM_funcs.h"
* located in https://code.google.com/p/blinkm-projects/
*
*
* 2007-14, Tod E. Kurt, ThingM, http://thingm.com/
*
*/
#ifndef BLINKM_H
#define BLINKM_H
#include <Arduino.h>
#include <Wire.h> // must also include Wire.h in your sketch
#include <inttypes.h>
#ifndef byte
#define byte uint8_t
#endif
const int defaultPwrPin = A2;
const int defaultGndPin = A3;
typedef struct {
byte dur;
byte cmd[4]; // cmd,arg1,arg2,arg3
} blinkm_script_line;
class BlinkM
{
private:
byte addr; // can only talk to one BlinkM at a time, use talkTo to change
byte gndPin;
byte pwrPin;
public:
BlinkM(void);
BlinkM( byte addr );
void begin(void);
void begin(byte addr);
void talkTo(byte address);
byte getTalkToAddress();
void setPowerPins(byte pwrpin, byte gndpin);
void powerUp(void);
void powerDown(void);
static int8_t FindFirstI2CDevice(void);
static void ScanI2CBus(byte from, byte to,
void(*callback)(byte add, byte result) );
void changeAddress(byte address);
int getAddress(void);
int checkAddress(void);
int getVersion(void);
void sendCmd(byte* cmd, int cmdlen);
int receiveBytes(byte* resp, byte len);
void setFadeSpeed(byte fadespeed);
void setFadeSpeed(byte fadespeed, byte naddr);
void setTimeAdj(byte timeadj);
void setTimeAdj(byte timeadj, byte naddr);
void fadeToRGB(byte red, byte grn, byte bri );
void fadeToRGB(byte red, byte grn, byte bri, byte naddr );
void fadeToHSB(byte hue, byte sat, byte bri );
void fadeToHSB(byte hue, byte sat, byte bri, byte naddr );
void setRGB(byte red, byte grn, byte blu);
void setRGB(byte red, byte grn, byte blu, byte naddr);
void getRGBColor(byte* red, byte* grn, byte* blu);
void fadeToRandomRGB(byte rrnd, byte grnd, byte brnd);
void fadeToRandomHSB(byte hrnd, byte srnd, byte brnd);
void playScript(byte script_id, byte reps, byte pos);
void playScript(byte script_id, byte reps, byte pos, byte naddr);
void stopScript( void );
void stopScript( byte naddr );
void off(void);
void off(byte naddr);
void setScriptLengthReps(byte script_id, byte len, byte reps );
void readScriptLine(byte script_id, byte pos,
blinkm_script_line* script_line);
void writeScriptLine(byte script_id, byte pos, byte dur,
byte cmd, byte arg1, byte arg2,byte arg3);
void writeScript(byte script_id, byte len, byte reps,
blinkm_script_line* lines);
void setStartupParams(byte mode, byte script_id,
byte reps, byte fadespeed, byte timeadj);
int getInputs(byte inputs[]);
int doFactoryReset(void);
// BlinkM2 commands
void setLEDn(byte ledn);
void setBrightness(byte brightness);
void mk2rotateLEDs(byte rot);
};
//extern BlinkMClass BlinkM;
#endif