Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1882 | - | 1 | #include "LPD8806_kopterlight_EXT.h" |
2 | #include "SPI.h" |
||
3 | |||
4 | /*****************************************************************************/ |
||
5 | // Kopter light control on LPD8806-based RGB LED Modules in a strip! |
||
6 | /*****************************************************************************/ |
||
7 | |||
8 | /*****************************************************************************/ |
||
9 | // To be changed according to your setup |
||
10 | /*****************************************************************************/ |
||
11 | // Remote control |
||
12 | // 0 = OFF ( default ) |
||
13 | // 1 = Digital input |
||
14 | // 2 = PWM input |
||
15 | uint8_t RMTCT = 0; |
||
16 | |||
17 | uint8_t NBSWLS = 4; // Number of switchabel light effects. (default: 10) |
||
18 | |||
19 | uint16_t rigger = 6; // number of rigger (default: 4) |
||
20 | uint16_t riggerSize = 10; // Pixels / LEDs per rigger (default: 10) |
||
21 | |||
22 | /*****************************************************************************/ |
||
23 | //Do not change or remove these! |
||
24 | /*****************************************************************************/ |
||
25 | |||
26 | uint16_t stripSize = (riggerSize*rigger); // Calculate total strip size. |
||
27 | |||
28 | // HW SPI |
||
29 | // on Arduino 168/328 thats data = 11, and clock = pin 13 |
||
30 | LPD8806 strip = LPD8806(stripSize, rigger); |
||
31 | |||
32 | // Pin definition for external input. |
||
33 | uint8_t InputJ16 = 8 ; // Arduino D8 |
||
34 | uint8_t InputPWM = 9 ; // Arduino D9 |
||
35 | int PWMin; |
||
36 | |||
37 | // Variable preset |
||
38 | uint8_t readStateJ16 = 0; |
||
39 | uint8_t readStateJ16HIGH = 0; |
||
40 | uint8_t counter1 =0; |
||
41 | uint8_t counter2 =0; |
||
42 | |||
43 | |||
44 | void setup() { |
||
45 | // Start up the LED strip |
||
46 | strip.begin(); |
||
47 | // Update the strip, to start with all LEDs 'off' |
||
48 | strip.show(); |
||
49 | clearstrip (); |
||
50 | NBSWLS = NBSWLS+1; |
||
51 | // Setup pinMode on Arduino pins |
||
52 | pinMode (InputJ16, INPUT); |
||
53 | pinMode (InputPWM, INPUT); |
||
54 | digitalWrite(InputJ16, HIGH); // Activate internal pullup |
||
55 | // digitalWrite(InputPWM, HIGH); // Activate internal pullup (Spare, if needed) |
||
56 | } |
||
57 | |||
58 | // ------------------------------------------------------------------ |
||
59 | // Remote Controll to select Light Sequence |
||
60 | // ------------------------------------------------------------------ |
||
61 | void remoteControl(){ |
||
62 | switch (RMTCT){ |
||
63 | case 0: |
||
64 | counter1 = 0; |
||
65 | break; |
||
66 | case 1: |
||
67 | readStateJ16 = digitalRead(InputJ16); // Trigger for Light Sequences |
||
68 | if (readStateJ16 == LOW){ |
||
69 | readStateJ16HIGH = 1; |
||
70 | } |
||
71 | if (readStateJ16==HIGH && readStateJ16HIGH == 1){ |
||
72 | counter1++; |
||
73 | readStateJ16HIGH = 0; |
||
74 | } |
||
75 | if(counter1 == (NBSWLS)){ |
||
76 | counter1 = 0; |
||
77 | } |
||
78 | break; |
||
79 | case 2: |
||
80 | PWMin = pulseIn(InputPWM, HIGH, 25000); // PWM signal to select Light Sequence |
||
81 | counter1= map(PWMin,1000,2000,0,NBSWLS); // Map PWM signal to defined steps |
||
82 | break; |
||
83 | } |
||
84 | } |
||
85 | |||
86 | // ------------------------------------------------------------------ |
||
87 | // Change strip config during runtime (Number of rigger, LEDs per rigger) |
||
88 | // ------------------------------------------------------------------ |
||
89 | void updateStripConfig (uint8_t rCount, uint8_t rSize){ |
||
90 | rigger = rCount; // number of rigger (default: 4) |
||
91 | riggerSize = rSize; // Pixels / LEDs per rigger (default: 10) |
||
92 | stripSize = (riggerSize*rigger); |
||
93 | strip.updateLength(stripSize, rigger); |
||
94 | } |
||
95 | |||
96 | // ------------------------------------------------------------------ |
||
97 | // Clear strip : Set all LEDs to dark |
||
98 | // ------------------------------------------------------------------ |
||
99 | void clearstrip (){ |
||
100 | for (int i=0; i < stripSize; i++) { |
||
101 | strip.setPixelColor(i,0,0,0,1,1,1,1,1,1,1,1); |
||
102 | } |
||
103 | } |
||
104 | |||
105 | // ------------------------------------------------------------------ |
||
106 | // Set single LED on selected rigger |
||
107 | // ------------------------------------------------------------------ |
||
108 | void setLED(uint16_t n, uint8_t r, uint8_t g, uint8_t b, uint8_t r1, uint8_t r2, uint8_t r3, uint8_t r4, uint8_t r5, uint8_t r6, uint8_t r7, uint8_t r8){ |
||
109 | n=n-1; |
||
110 | remoteControl(); |
||
111 | if (counter1 != counter2) { |
||
112 | return;} |
||
113 | strip.setPixelColor(n, r, g, b, r1, r2, r3, r4, r5, r6, r7, r8); |
||
114 | } |
||
115 | |||
116 | |||
117 |