Hi all, Still very new and learning the language as I go. I am trying to use Arduino to run a few separate functions based on position of a joystick. I have separated each task into a function to help me keep the code clearer (for me).
What I am noticing is the LEDS do not turn off after the joystick position is reset. I have tried FastLED.clear(true); but maybe I have been putting it in the wrong place?
Additionally, once I get that working, it would be good to have an Everything on at once option. I assume I can do this with a separate function, however not sure as it appears I can't separate FastLED.addleds for each function...(
EDIT I have since discovered this is because the NUM_LEDS and DATA_PIN need to be constant. How can I get around this, Ie do a new FastLED instance per target LEDS?
FastLED.addLeds<WS2812, Smoke_LED, GRB>(leds, NUM_LEDS); //2 lEDS
FastLED.addLeds<WS2812, Head_LED, GRB>(leds, NUM_LEDS); // 2 LEDS
FastLED.addLeds<WS2812, Jaw_LED, GRB>(leds, NUM_LEDS); // 3 LEDS
So the current situation is the LEDS all come on and blink at the same time. I need to separate them
Thank you.
#include "FastLED.h"
// Arduino Input PIN numbers
const int Switch_Pin = 2; // digital pin connected to switch output
const int X_Pin = 0; // analog pin connected to X output
const int Y_Pin = 1; // analog pin connected to Y output
//Outputs
const int Smoke_Pin = 3; // pin for smoke uses digital pins
const int Smoke_LED = 4; // For Smoke LED
const int Head_Pin = 9; // pin for Y direction up (0)
const int Jaw_Pin = 6; // pin for Y directio
void setup()
{
randomSeed(analogRead(0));
// put your setup code here, to run once:
// initialize digital pins
pinMode(Smoke_Pin, OUTPUT);
pinMode(Switch_Pin, INPUT);
digitalWrite(Switch_Pin, HIGH);
digitalWrite(Smoke_Pin, LOW);
digitalWrite(Smoke_LED, OUTPUT);
digitalWrite(Smoke_LED, LOW);
digitalWrite(Head_Pin, OUTPUT);
digitalWrite(Head_Pin, LOW);
digitalWrite(Jaw_Pin, OUTPUT);
digitalWrite(Jaw_Pin, LOW);
Serial.begin(115200);
}
void loop()
{
//Monitor -
Serial.print("=====================INPUTS=====================");
Serial.print("\n");
Serial.print("Switch_Pin :");
Serial.print(digitalRead(Switch_Pin));
Serial.print("\n");
Serial.print("X Value :");
Serial.print(analogRead(X_Pin));
Serial.print("\n");
Serial.print("Y Value :");
Serial.print(analogRead(Y_Pin));
Serial.print("\n");
Serial.print("\n");
Serial.print("\n");
Serial.print("=====================OUTPUTS=====================");
Serial.print("\n");
Serial.print("Smoke_Pin :");
Serial.print(analogRead(Smoke_Pin));
Serial.print("\n");
Serial.print("Smoke_LED :");
Serial.print(analogRead(Smoke_LED));
Serial.print("\n");
Serial.print("Head_Pin :");
Serial.print(analogRead(Head_Pin));
Serial.print("\n");
Serial.print("Jaw_Pin :");
Serial.print(analogRead(Jaw_Pin));
Serial.print("\n");
////////////////////Monitor Joystick / switches here
//SMOKE PIN PRESSED
if (digitalRead(Switch_Pin == 0))
{
Smoke();
}
//JAW PIN PRESSED
if (analogRead(Y_Pin) > 1000)
{
Jaw();
}
//HEAD PIN PRESSED
if (analogRead(Y_Pin) < 50)
{
Head();
}
FastLED.clear(true);
}
//**********FUNCTIONS***********
//SMOKE////////////////////////
void Smoke()
{
CRGB leds[2];
FastLED.addLeds<WS2812, Smoke_LED, GRB>(leds, 2); //Pin number 4
int8_t H = random(0,20); //HUE
int8_t S = random(250,256); //SAT
int8_t V = random(250,256); //BRIGHT
leds[0] = CHSV(H,S,V);
leds[1] = CHSV(H,S,V);
FastLED.show();
//makes white run quicker
if ((H <= 30) && (S >= 0 && S <= 200) && (V <= 200))
{
// white
delay(1);
}
else
{
// not white
delay(500);
}
// Activates smoke IE activatea pin 3 as active
digitalWrite(Smoke_Pin, HIGH);
delay(1000);
}
//SMOKE///////////////////////
///////////////HORNS - JAW/////////////////////////////////////////////////
void Jaw()
{
CRGB leds[3];
FastLED.addLeds<WS2812, Jaw_Pin, GRB>(leds, 3); //Pin number 6
int8_t H = random(0,50); //HUE
int8_t S = random(60,256); //SAT
int8_t V = random(200,256); //BRIGHT
//middle horn
leds[1] = CHSV(H,S,V);
FastLED.show();
// below for edge horns to be same
H = random(0,50); //HUE
S = random(150,256); //SAT
V = random(180,230); //BRIGHT
leds[0] = CHSV(H,S,V);
leds[2] = CHSV(H,S,V);
FastLED.show();
//makes white run quicker
if ((H <= 30) && (S >= 0 && S <= 200) && (V <= 200))
{
// white
delay(1);
}
else
{
// not white
delay(70);
}
}
//////HORNS JAW////////////////////////////////////////////////////////
///////////////HORNS - HEAD/////////////////////////////////////////////////
void Head()
{
CRGB leds[2];
FastLED.addLeds<WS2812, Head_Pin, GRB>(leds, 2); //Pin number 9
int8_t H = random(0,20); //HUE
int8_t S = random(250,256); //SAT
int8_t V = random(250,256); //BRIGHT
leds[0] = CHSV(H,S,V);
leds[1] = CHSV(H,S,V);
FastLED.show();
//makes white run quicker
if ((H <= 30) && (S >= 0 && S <= 200) && (V <= 200))
{
// white
delay(1);
}
else
{
// not white
delay(500);
}
}
//////HORNS JAW////////////////////////////////////////////////////////