Im looking to run two or sometimes three of these animations "simultaneously". I've read up on kriegsman's post about running two animations at once, and while that is ultimately helpful, it seems to rely on using the built-in animations in the FastLED Library. I can't seem to find a way to apply my animations to his coding example. Furthermore, I've read blinking without delay and I believe I understand the basis of it, though my animations rely on some sort of time delay to function properly. I've entertained the idea of re-writing my animations to encompass what is now separate animations, but I've run into roadblocks there as well.
In short, what I'm looking to do is run say, bSwirl and tDrain, at what appears to be the same time but I can't figure out a way to achieve that. I'm using an Arduino Uno board, a 5M strip of LPD8806 LEDs, and a button in this project.
The code I've written is sincerely a hodgepodge of code from all over the place. I'm not going to pretend I know precisely what I'm doing, but I'm willing to give my best efforts to it. I just need some guidance if thats at all possible. I've only got about two weeks of experience under my belt so far and what I know I've learned without assistance.
Also, I know I should be commenting more in my code, I've just gotten away from it. I intend to ament this code to include comments in future.
#include <Arduino.h>
#include <FastLED.h>
#define NUM_LEDS 160
#define DATA_PIN 6
#define CLOCK_PIN 13
#define FORWARD 0
#define BACKWARD 1
#define BRIGHTNESS 96
#define FRAMES_PER_SECOND 100
CRGB leds[NUM_LEDS];
const int buttonPin = 2;
//SETUP//
void setup() {
delay(3000);
pinMode(buttonPin, INPUT); // sets button 2 to input
Serial.begin(9600); // sets baud rate for serial comm to 9600
FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, BRG>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
for (int iT = 0; iT < 59; iT++) {
leds[iT] = CRGB::Black;
}
for (int iB = 60; iB < 119; iB++) {
leds[iB] = CRGB::Black;
}
for (int iD = 120; iD < 159; iD++) {
leds[iD] = CRGB::Black;
}
FastLED.show();
}
//loop//
void loop() {
preRun();
while (digitalRead(buttonPin) == HIGH) {}
bSwirl(0, 255, 255);
tDrain(CRGB::Black, 0);
bDrain(CRGB::Black, 0);
drain(128, 0, 0);
dDrain(CRGB::Black, 0);
bFill(CRGB::Aqua, 1);
tFill(CRGB::Blue, 1);
}
//preRun//
void preRun() {
for (int iT = 0; iT < 59; iT++) {
leds[iT] = CRGB::Blue;
}
for (int iB = 60; iB < 119; iB++) {
leds[iB] = CRGB::Aqua;
}
FastLED.show();
}
//bSwirl//
void bSwirl(uint32_t r, uint32_t g, uint32_t b) {
for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
for (int q = 0; q < 3; q++) {
for (int i = 60; i < 119; i = i + 3) {
//turn every third pixel on
leds[i + q].r = r;
leds[i + q].g = g;
leds[i + q].b = b;
}
FastLED.show();
timeLoop(millis(), 100);
for (int i = 60; i < 119; i = i + 3) {
//turn every third pixel off
leds[i + q].r = 0;
leds[i + q].g = 0;
leds[i + q].b = 0;
}
}
}
for (int j = 0; j < 1; j++) { //do 1 cycles of chasing
for (int q = 0; q < 3; q++) {
for (int i = 60; i < 119; i = i + 3) {
//turn every third pixel on
leds[i + q].r = r;
leds[i + q].g = g;
leds[i + q].b = b;
}
FastLED.show();
timeLoop(millis(), 100);
for (int i = 60; i < 119; i = i + 3) {
//turn every third pixel off
leds[i + q].r = r;
leds[i + q].g = g;
leds[i + q].b = b;
}
}
}
}
//drain//
void drain(uint32_t r, uint32_t g, uint32_t b) {
for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
for (int q = 0; q < 3; q++) {
for (int i = 120; i < 159; i = i + 3) {
//turn every third pixel on
leds[i + q].r = r;
leds[i + q].g = g;
leds[i + q].b = b;
}
FastLED.show();
timeLoop(millis(), 100);
for (int i = 120; i < 159; i = i + 3) {
//turn every third pixel off
leds[i + q].r = 0;
leds[i + q].g = 0;
leds[i + q].b = 0;
}
}
}
for (int j = 0; j < 1; j++) { //do 1 cycles of chasing
for (int q = 0; q < 3; q++) {
for (int i = 120; i < 159; i = i + 3) {
//turn every third pixel on
leds[i + q].r = r;
leds[i + q].g = g;
leds[i + q].b = b;
}
FastLED.show();
timeLoop(millis(), 100); //delay speed
for (int i = 120; i < 159; i = i + 3) {
//turn every third pixel off
leds[i + q].r = r;
leds[i + q].g = g;
leds[i + q].b = b;
}
}
}
}
//timeLoop//
void timeLoop (long int startMillis, long int interval) { // delay substitute function
// this loops until "n" milliseconds has passed since the function began
while (millis() - startMillis < interval) {}
}
//bDrain//
void bDrain(CRGB c, int direction) {
for (int i = 60; i < 120; i++) {
if (direction == FORWARD) {
leds[i] = c;
}
else {
leds[119 - 1 - i] = c;
}
FastLED.show();
timeLoop(millis(), 50); // speed at which colors chase to black
}
}
//tDrain//
void tDrain(CRGB c, int direction) {
for (int i = 0; i < 60; i++) {
if (direction == FORWARD) {
leds[i] = c;
}
else {
leds[60 - 1 - i] = c;
}
FastLED.show();
timeLoop(millis(), 50);
}
}
//dDrain//
void dDrain(CRGB c, int direction) {
for (int i = 120; i < 159; i++) {
if (direction == FORWARD) {
leds[i] = c;
}
else {
leds[120 - 1 - i] = c;
}
FastLED.show();
timeLoop(millis(), 50);
}
}
//bFill//
void bFill(CRGB c, int direction) {
for (int i = 119; i > 60; i--) {
if (direction == BACKWARD) {
leds[i] = c;
}
else {
leds[60 + 1 + i] = c;
}
FastLED.show();
timeLoop(millis(), 50);
}
}
//tFill//
void tFill(CRGB c, int direction) {
for (int i = 59; i > 0; i--) {
if (direction == BACKWARD) {
leds[i] = c;
}
else {
leds[0 + 1 + i] = c;
}
FastLED.show();
timeLoop(millis(), 50);
}
}