30 #include "utility/twi.h" 61 void(*
callback)(byte add, byte result) )
65 for( byte addr = from; addr <= to; addr++ ) {
66 rc = twi_writeTo(addr, &data, 0, 1, 1);
77 for( byte addr=1; addr < 120; addr++ ) {
78 rc = twi_writeTo(addr, &data, 0, 1, 1);
79 if( rc == 0 )
return addr;
87 DDRC |= _BV(pwrpin) | _BV(gndpin);
88 PORTC &=~ _BV(gndpin);
95 DDRC &=~ (_BV(pwrpin) | _BV(gndpin));
129 Wire.beginTransmission(addr);
130 for( byte i=0; i<cmdlen; i++)
132 Wire.endTransmission();
140 Wire.requestFrom(addr, len);
141 if( Wire.available() ) {
142 for(
int i=0; i<len; i++)
143 resp[i] = Wire.read();
153 Wire.beginTransmission(0x00);
155 Wire.write(newaddress);
158 Wire.write(newaddress);
159 Wire.endTransmission();
169 Wire.beginTransmission(addr);
171 Wire.endTransmission();
172 Wire.requestFrom(addr, (byte)1);
173 if( Wire.available() ) {
174 byte b = Wire.read();
183 Wire.beginTransmission(addr);
185 Wire.endTransmission();
186 Wire.requestFrom(addr, (byte)2);
187 if( Wire.available() ) {
188 byte major_ver = Wire.read();
189 byte minor_ver = Wire.read();
190 return (major_ver<<8) + minor_ver;
217 Wire.beginTransmission(addr);
219 Wire.write(fadespeed);
220 Wire.endTransmission();
228 Wire.beginTransmission(addr);
231 Wire.endTransmission();
237 Wire.beginTransmission(addr);
242 Wire.endTransmission();
248 Wire.beginTransmission(addr);
251 Wire.write(saturation);
252 Wire.write(brightness);
253 Wire.endTransmission();
259 Wire.beginTransmission(addr);
264 Wire.endTransmission();
270 Wire.beginTransmission(addr);
275 Wire.endTransmission();
280 Wire.beginTransmission(addr);
285 Wire.endTransmission();
291 Wire.beginTransmission(addr);
293 Wire.endTransmission();
294 Wire.requestFrom(addr, (byte)3);
295 if( Wire.available() ) {
305 Wire.beginTransmission(addr);
307 Wire.write(script_id);
310 Wire.endTransmission();
316 Wire.beginTransmission(addr);
318 Wire.endTransmission();
325 Wire.beginTransmission(addr);
327 Wire.write(script_id);
330 Wire.endTransmission();
338 Wire.beginTransmission(addr);
340 Wire.write(script_id);
342 Wire.endTransmission();
343 Wire.requestFrom(addr, (byte)5);
344 while( Wire.available() < 5 ) ;
345 script_line->
dur = Wire.read();
346 script_line->
cmd[0] = Wire.read();
347 script_line->
cmd[1] = Wire.read();
348 script_line->
cmd[2] = Wire.read();
349 script_line->
cmd[3] = Wire.read();
355 byte
cmd, byte arg1, byte arg2, byte arg3)
357 #ifdef BLINKM_FUNCS_DEBUG 358 Serial.print(
"writing line:"); Serial.print(pos,DEC);
359 Serial.print(
" with cmd:"); Serial.print(cmd);
360 Serial.print(
" arg1:"); Serial.println(arg1,HEX);
362 Wire.beginTransmission(addr);
364 Wire.write(script_id);
371 Wire.endTransmission();
380 #ifdef BLINKM_FUNCS_DEBUG 381 Serial.print(
"writing script to addr:"); Serial.print(addr,DEC);
382 Serial.print(
", script_id:"); Serial.println(script_id,DEC);
384 for(byte i=0; i < len; i++) {
395 byte reps, byte fadespeed, byte timeadj)
397 Wire.beginTransmission(addr);
400 Wire.write(script_id);
402 Wire.write(fadespeed);
404 Wire.endTransmission();
412 Wire.beginTransmission(addr);
414 Wire.endTransmission();
415 Wire.requestFrom(addr, (byte)1);
416 if( Wire.available() ) {
417 byte b = Wire.read();
428 Wire.beginTransmission(addr);
430 Wire.endTransmission();
431 Wire.requestFrom(addr, (byte)4);
432 while( Wire.available() < 4 ) ;
434 inputs[0] = Wire.read();
435 inputs[1] = Wire.read();
436 inputs[2] = Wire.read();
437 inputs[3] = Wire.read();
static int BlinkM_receiveBytes(byte addr, byte *resp, byte len)
static void BlinkM_setTimeAdj(byte addr, byte timeadj)
static void BlinkM_getRGBColor(byte addr, byte *r, byte *g, byte *b)
static void BlinkM_setAddress(byte newaddress)
static void BlinkM_stopScript(byte addr)
static void BlinkM_stopPowerWithPins(byte pwrpin, byte gndpin)
static void BlinkM_writeScript(byte addr, byte script_id, byte len, byte reps, blinkm_script_line *lines)
static void BlinkM_setScriptLengthReps(byte addr, byte script_id, byte len, byte reps)
static void BlinkM_writeScriptLine(byte addr, byte script_id, byte pos, byte dur, byte cmd, byte arg1, byte arg2, byte arg3)
static void BlinkM_startPowerWithPins(byte pwrpin, byte gndpin)
static int BlinkM_getInputsO(byte addr)
static void BlinkM_sendCmd(byte addr, byte *cmd, int cmdlen)
static int BlinkM_getAddress(byte addr)
static void BlinkM_beginWithPowerPins(byte pwrpin, byte gndpin)
struct _blinkm_script_line blinkm_script_line
static void BlinkM_setFadeSpeed(byte addr, byte fadespeed)
static void BlinkM_fadeToHSB(byte addr, byte hue, byte saturation, byte brightness)
static void BlinkM_startPower()
static void BlinkM_stopPower()
static void BlinkM_scanI2CBus(byte from, byte to, void(*callback)(byte add, byte result))
static void BlinkM_readScriptLine(byte addr, byte script_id, byte pos, blinkm_script_line *script_line)
static void BlinkM_setRGB(byte addr, byte red, byte grn, byte blu)
static void BlinkM_begin()
static int8_t BlinkM_findFirstI2CDevice()
static void BlinkM_fadeToRandomRGB(byte addr, byte rrnd, byte grnd, byte brnd)
static void BlinkM_setStartupParams(byte addr, byte mode, byte script_id, byte reps, byte fadespeed, byte timeadj)
static void BlinkM_beginWithPower()
static void BlinkM_fadeToRGB(byte addr, byte red, byte grn, byte blu)
static void BlinkM_playScript(byte addr, byte script_id, byte reps, byte pos)
static int BlinkM_getVersion(byte addr)
static void BlinkM_fadeToRandomHSB(byte addr, byte hrnd, byte srnd, byte brnd)
static int BlinkM_getInputs(byte addr, byte inputs[])
static int BlinkM_checkAddress(byte addr)