0,0 → 1,117 |
#include "LPD8806_kopterlight_EXT.h" |
#include "SPI.h" |
|
/*****************************************************************************/ |
// Kopter light control on LPD8806-based RGB LED Modules in a strip! |
/*****************************************************************************/ |
|
/*****************************************************************************/ |
// To be changed according to your setup |
/*****************************************************************************/ |
// Remote control |
// 0 = OFF ( default ) |
// 1 = Digital input |
// 2 = PWM input |
uint8_t RMTCT = 0; |
|
uint8_t NBSWLS = 4; // Number of switchabel light effects. (default: 10) |
|
uint16_t rigger = 6; // number of rigger (default: 4) |
uint16_t riggerSize = 10; // Pixels / LEDs per rigger (default: 10) |
|
/*****************************************************************************/ |
//Do not change or remove these! |
/*****************************************************************************/ |
|
uint16_t stripSize = (riggerSize*rigger); // Calculate total strip size. |
|
// HW SPI |
// on Arduino 168/328 thats data = 11, and clock = pin 13 |
LPD8806 strip = LPD8806(stripSize, rigger); |
|
// Pin definition for external input. |
uint8_t InputJ16 = 8 ; // Arduino D8 |
uint8_t InputPWM = 9 ; // Arduino D9 |
int PWMin; |
|
// Variable preset |
uint8_t readStateJ16 = 0; |
uint8_t readStateJ16HIGH = 0; |
uint8_t counter1 =0; |
uint8_t counter2 =0; |
|
|
void setup() { |
// Start up the LED strip |
strip.begin(); |
// Update the strip, to start with all LEDs 'off' |
strip.show(); |
clearstrip (); |
NBSWLS = NBSWLS+1; |
// Setup pinMode on Arduino pins |
pinMode (InputJ16, INPUT); |
pinMode (InputPWM, INPUT); |
digitalWrite(InputJ16, HIGH); // Activate internal pullup |
// digitalWrite(InputPWM, HIGH); // Activate internal pullup (Spare, if needed) |
} |
|
// ------------------------------------------------------------------ |
// Remote Controll to select Light Sequence |
// ------------------------------------------------------------------ |
void remoteControl(){ |
switch (RMTCT){ |
case 0: |
counter1 = 0; |
break; |
case 1: |
readStateJ16 = digitalRead(InputJ16); // Trigger for Light Sequences |
if (readStateJ16 == LOW){ |
readStateJ16HIGH = 1; |
} |
if (readStateJ16==HIGH && readStateJ16HIGH == 1){ |
counter1++; |
readStateJ16HIGH = 0; |
} |
if(counter1 == (NBSWLS)){ |
counter1 = 0; |
} |
break; |
case 2: |
PWMin = pulseIn(InputPWM, HIGH, 25000); // PWM signal to select Light Sequence |
counter1= map(PWMin,1000,2000,0,NBSWLS); // Map PWM signal to defined steps |
break; |
} |
} |
|
// ------------------------------------------------------------------ |
// Change strip config during runtime (Number of rigger, LEDs per rigger) |
// ------------------------------------------------------------------ |
void updateStripConfig (uint8_t rCount, uint8_t rSize){ |
rigger = rCount; // number of rigger (default: 4) |
riggerSize = rSize; // Pixels / LEDs per rigger (default: 10) |
stripSize = (riggerSize*rigger); |
strip.updateLength(stripSize, rigger); |
} |
|
// ------------------------------------------------------------------ |
// Clear strip : Set all LEDs to dark |
// ------------------------------------------------------------------ |
void clearstrip (){ |
for (int i=0; i < stripSize; i++) { |
strip.setPixelColor(i,0,0,0,1,1,1,1,1,1,1,1); |
} |
} |
|
// ------------------------------------------------------------------ |
// Set single LED on selected rigger |
// ------------------------------------------------------------------ |
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){ |
n=n-1; |
remoteControl(); |
if (counter1 != counter2) { |
return;} |
strip.setPixelColor(n, r, g, b, r1, r2, r3, r4, r5, r6, r7, r8); |
} |
|
|
|