Hi all,
trying to a rainbow chase with FastLed, what would i have to do rather than it chasing as it is at the moment?
// Use if you want to force the software SPI subsystem to be used for some reason (generally, you don’t)
// #define FORCE_SOFTWARE_SPI
// Use if you want to force non-accelerated pin access (hint: you really don’t, it breaks lots of things)
// #define FORCE_SOFTWARE_SPI
// #define FORCE_SOFTWARE_PINS
#include “FastLED.h”
///////////////////////////////////////////////////////////////////////////////////////////
//
// Move a white dot along the strip of leds. This program simply shows how to configure the leds,
// and then how to turn a single pixel white and then off, moving down the line of pixels.
//
// How many leds are in the strip?
#define NUM_LEDS 52
// Data pin that led data will be written out over
#define DATA_PIN 2
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define CLOCK_PIN 3
// This is an array of leds. One item for each led in your strip.
CRGB leds[NUM_LEDS];
const int buttonPin = 4; // the number of the pushbutton pin
const int ledPin = 2; // the number of the LED pin
const int ledWhite = 13; // the number of the LED pin
const int pinNumber = 13;
// variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int ledState = LOW; // ledState used to set the LED
// Generally, you should use “unsigned long” for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won’t change :
const long interval = 1000; // interval at which to blink (milliseconds)
// This function sets up the ledsand tells the controller about them
void setup() {
// sanity check delay - allows reprogramming if accidently blowing power w/leds
delay(2000);
pinMode(ledWhite, OUTPUT);
// Uncomment 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<WS2811_400, 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<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903B, 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<P9813, 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);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
//SETTING REST STATE
void setSameColor(byte r, byte g, byte b)
{
for (int i=0;i<NUM_LEDS;i++) leds[i]=CRGB(0,0,255);
FastLED.show();
}
//SETTING PRESS STATE
void setColorChase(unsigned long time)
{
memset(leds,0,sizeof(leds));
for (int i=0;i<15;i++) // 20 leds
leds[(time+i)%NUM_LEDS]=CRGB(255,0,0);
// red?
digitalWrite(pinNumber, (millis()/500)%2);
FastLED.show();
}
#define STEPDURATION 10
#define CHASEDURATION 6000
unsigned long stepTime;
unsigned long lastLEDupdate;
unsigned long lastButtonPress=-CHASEDURATION;
void loop()
{
;
// read button input and remember the time if the button was pressed
if (millis()-lastButtonPress>=CHASEDURATION)
{
boolean pressed=digitalRead(buttonPin);
if (pressed) lastButtonPress=millis();
}
// check if it is time to set new colors
if
(millis()-lastLEDupdate>=STEPDURATION)
{
lastLEDupdate+=STEPDURATION;
stepTime++;
digitalWrite(pinNumber, HIGH);
if (millis()-lastButtonPress>=CHASEDURATION) // button press is long time ago
setSameColor(0, 50, 50); // show same color (white with ‘nearly full intensity’)
else
setColorChase(stepTime); // color chase
}
}
Thanks