#include "FastLED.h"
#include <dot.h>
#include <dbswitch.h>
// How many leds in your strip?
#define NUM_LEDS 96
#define NUM_SPOTS 32
// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 11
#define CLOCK_PIN 12
#define NUM_SPOTS 32
#define DELAY_TIME 30
#define VALUE_THRESHHOLD 2000
#define BOUNCE_TIME 150
#define NUM_EFFECTS 2
DBSwitch::DBSwitch( unsigned char pinNum, int delayTime )
{
pin = pinNum;
lastRead = touchRead( pin ) > VALUE_THRESHHOLD;
lastRead = state;
count = 0;
leadingEdge = 0;
trailingEdge = 0;
if ( delayTime >= BOUNCE_TIME )
bounceThreshhold = 2;
else
bounceThreshhold = ( delayTime + BOUNCE_TIME - 1 ) / BOUNCE_TIME;
}
void DBSwitch::Update( void )
{
unsigned char value = touchRead( pin ) > VALUE_THRESHHOLD; // convert to a digital signal
if ( value == lastRead ) // if input has NOT changed since last update
{
if ( lastRead == state ) // ignore if the state is the same - clear leading & trailing edges
{
leadingEdge = 0;
trailingEdge = 0;
}
else if ( ++count > bounceThreshhold ) // if this is a valid change in state. Count in any event
{
state = lastRead;
count = 0;
leadingEdge = state;
trailingEdge = state == 0;
}
}
else // input value changed since last update. start counting
{
lastRead = value;
count = 0;
}
}
unsigned char DBSwitch::State( void )
{
return state;
}
unsigned char DBSwitch::LeadingEdge( void )
{
return leadingEdge;
}
unsigned char DBSwitch::TrailingEdge( void )
{
return trailingEdge;
}
// Define the array of leds
CRGB leds[NUM_LEDS];
LEDDot dotString[ NUM_SPOTS ]; // these represent physical dots
Spot redSpot;
Spot pulseVioletSpot;
Spot pulseGreenSpot;
DBSwitch touchSwitch( 23, DELAY_TIME );
int effect = 0;
void setup()
{
pinMode( 13, OUTPUT );
// Uncomment/edit one of the following lines for your leds arrangement.
// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
CRGB dimViolet = CRGB( 8, 0, 8 );
// initialize the LEDs that are in use
for( int i = 0; i < NUM_SPOTS; ++i )
{
dotString[i].clear();
dotString[i].setBaseColor( dimViolet );
dotString[i].reset();
}
// initialize our virtual spots (sections)
redSpot.Init( 9.0, 0.0, 0.20, CRGB::DarkRed );
pulseVioletSpot.Init( 12.0, 16.0, 1.0/30.0, CRGB( 32, 0 , 28 ) );
pulseGreenSpot.Init( 48.0, 16.0, 1.0/30.0, CRGB::DarkGreen );
}
void loop()
{
digitalWrite( 13, HIGH ); // prove that we get to the loop at least once
for ( unsigned char i = 0; i < NUM_SPOTS; ++i )
{
switch( effect ) // allow the user to switch effects
{
case 0:
pulseVioletSpot.PopulateDot( dotString[i], i, (bool)true ); // affect this physical dot with the pusling violet Spot
redSpot.PopulateDot( dotString[i], i, (bool)false ); // affect this physical dot with the red Spot
break;
case 1:
pulseGreenSpot.PopulateDot( dotString[i], i, (bool)true ); // affect this physical dot with the green Spot
break;
}
leds[i] = dotString[i].c; // output to the LEDs
}
FastLED.show();
FastLED.delay( DELAY_TIME );
if ( touchSwitch.LeadingEdge() ) // change effects
{
if ( ++effect >= NUM_EFFECTS )
effect = 0;
}
// update the position/color/size of the Spots
pulseVioletSpot.Pulse();
pulseGreenSpot.Pulse();
redSpot.Update( NUM_SPOTS );
// update the switch state
touchSwitch.Update();
}