-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
83 lines (75 loc) · 1.35 KB
/
main.cpp
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
/** RGB LED Strip (SPI)
*/
#include "mbed.h"
// SPI 1 oder 2, da kein SS
SPI spi( MBED_CONF_IOTKIT_LED_SPI_MOSI, NC, MBED_CONF_IOTKIT_LED_SPI_SCLK ); // mosi, miso, sclk
/** 3 x 3 Werte */
unsigned int strip[9];
void writeLED()
{
for ( int p = 0; p < 9; p++ )
spi.write( strip[p] );
}
void clearLED()
{
for ( int p = 0; p < 9; p++ )
{
strip[p] = 0;
spi.write( strip[p] );
}
}
int main()
{
printf( "LED Strip Test \n" );
spi.format( 8,0 );
spi.frequency( 800000 );
while (true)
{
// Gruen, Rot, Blau - von Dunkel bis Hell
for ( int i = 0; i < 128; i+=32 )
{
// LED 1
strip[0] = i;
strip[1] = 0;
strip[2] = 0;
// LED 2
strip[3] = 0;
strip[4] = i;
strip[5] = 0;
// LED 3
strip[6] = 0;
strip[7] = 0;
strip[8] = i;
writeLED();
thread_sleep_for( 100 );
}
thread_sleep_for( 1000 );
clearLED();
// Lauflicht (5 x 4 Zustaende)
int p = 0;
for ( int i = 0; i < 20; i++ )
{
p++;
switch ( p )
{
case 1:
strip[0] = strip[1] = strip[2] = 32;
break;
case 2:
strip[0] = strip[1] = strip[2] = 0;
strip[3] = strip[4] = strip[5] = 32;
break;
case 3:
strip[3] = strip[4] = strip[5] = 0;
strip[6] = strip[7] = strip[8] = 32;
break;
default:
clearLED();
p = 0;
break;
}
writeLED();
thread_sleep_for( 200 );
}
}
}