My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
/**
* BlinkM_funcs_soft.h -- an extremely cut-down version of BlinkM_funcs.h
* for use with SoftI2CMaster library
*
*
* 2010 Tod E. Kurt, http://todbot.com/blog/
*
*/

int errcnt;

static void BlinkM_begin()
{
// nothing to do here yet
}

//
static void BlinkM_beginWithPower(byte pwrpin, byte gndpin)
{
pinMode(pwrpin, OUTPUT);
pinMode(gndpin, OUTPUT);
digitalWrite(pwrpin, HIGH);
digitalWrite(gndpin, LOW);
}


// -----------------------------------------------------------------------------
static void BlinkM_sendCmd3( uint8_t addr, uint8_t c, uint8_t a1, uint8_t a2, uint8_t a3 )
{
if( i2c.beginTransmission( addr ) == 0 ) {
++errcnt;
//Serial.println( errcnt); // FIXME
}
i2c.send( c );
i2c.send( a1 );
i2c.send( a2 );
i2c.send( a3 );
i2c.endTransmission();
}

static void BlinkM_sendCmd1( uint8_t addr, uint8_t c, uint8_t a1)
{
if( i2c.beginTransmission( addr ) == 0 ) {
++errcnt;
//Serial.println( errcnt); // FIXME
}
i2c.send( c );
i2c.send( a1 );
}

static void BlinkM_stopScript(uint8_t addr)
{
i2c.beginTransmission( addr );
i2c.send( 'o' );
i2c.endTransmission();
}

static void BlinkM_setFadeSpeed( uint8_t addr, uint8_t f)
{
BlinkM_sendCmd1( addr, 'f', f );
}

static void BlinkM_fadeToRGB( uint8_t addr, uint8_t r, uint8_t g, uint8_t b )
{
BlinkM_sendCmd3( addr, 'c', r,g,b );
}

static void BlinkM_setRGB( uint8_t addr, uint8_t r, uint8_t g, uint8_t b )
{
BlinkM_sendCmd3( addr, 'n', r,g,b );
}

static void BlinkM_off(uint8_t addr)
{
BlinkM_stopScript( addr );
BlinkM_setFadeSpeed(addr,10);
BlinkM_setRGB(addr, 0,0,0 );
}

// Get the BlinkM firmware version
static int BlinkM_getVersion(byte addr)
{
i2c.beginTransmission( addr );
i2c.send( 'Z' );
i2c.endTransmission();

i2c.requestFrom( addr );
uint8_t major_ver = i2c.receive();
uint8_t minor_ver = i2c.receiveLast();
i2c.endTransmission();
return (major_ver<<8) + minor_ver;
}

//
static void BlinkM_getRGBColor(byte addr, byte* r, byte* g, byte* b)
{
i2c.beginTransmission(addr);
i2c.send('g');
i2c.endTransmission();

i2c.requestFrom( addr );
*r = i2c.receive();
*g = i2c.receive();
*b = i2c.receiveLast();
i2c.endTransmission();
}




Change log

r124 by tod.kurt on Jan 18, 2012   Diff
formatting changes
Go to: 
Project members, sign in to write a code review

Older revisions

r123 by tod.kurt on Jan 18, 2012   Diff
SoftI2CMaster now supports reads and
writes
r119 by tod.kurt on Dec 1, 2011   Diff
updated BlinkM_funcs.h, BlinkMTester,
BlinkMCommunicator, and
BlinkM_funcs_soft.h to work with
Arduino 1.0
r102 by tod.kurt on May 29, 2011   Diff
updated BlinkMCylon
All revisions of this file

File info

Size: 2379 bytes, 110 lines
Powered by Google Project Hosting