Salutations! I have 2 separate buttons to control the different LED's for my project. When the toggleSwitch is ON, the WATT_LED does not work how I intend. In a nutshell, I want the LED matrix to light and 5 LED chase effect when the toggleSwitch is ON. When the pushButton is ON, I want the WATT_LED to blink how I have it programmed. So at the moment, when the toggleSwitch is on, the WATT_LED does not blink. When the toggleSwitch is off, it works. How do I get them both to work at the same time? Should I write one in a separate function? Here is the code:
#include <FastLED.h>
#define LED_PIN 8
#define NUM_LEDS 64
#define toggleSwitch 2
#define pushButton 9
#define WATT_LED 10
CRGB leds[NUM_LEDS];
int ledPins[] = {3,4,5,6,7};
void setup() {
pinMode (toggleSwitch, INPUT);
int index;
for (index = 0; index <= 5; index++){
pinMode(ledPins, OUTPUT);
}
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
pinMode(WATT_LED, OUTPUT);
pinMode(pushButton, INPUT);
}
void loop() {
int switchState = digitalRead(toggleSwitch);
int buttonStatus = digitalRead (pushButton);
if (buttonStatus == HIGH) {
digitalWrite (WATT_LED, HIGH);
delay(250);
digitalWrite (WATT_LED, LOW);
delay (250);
}
else {
digitalWrite(WATT_LED, LOW);
delay(0);
}
if (switchState == HIGH) {
digitalWrite(ledPins[0], HIGH);
delay(100);
digitalWrite(ledPins[1], HIGH);
delay(100);
digitalWrite(ledPins[2], HIGH);
delay(100);
digitalWrite(ledPins[3], HIGH);
delay(100);
digitalWrite(ledPins[4], HIGH);
delay(100);
digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[3], LOW);
digitalWrite(ledPins[4], LOW);
delay(250);
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[1], HIGH);
digitalWrite(ledPins[2], HIGH);
digitalWrite(ledPins[3], HIGH);
digitalWrite(ledPins[4], HIGH);
}
if (switchState == HIGH){
for (int i = 0; i<64; i++) {
leds [i] = CRGB (0,0,255);
FastLED.show();
delay (100);
}
}
else {
for (int i = 0; i<64; i++){
leds[i] = CRGB (0,0,0);
FastLED.show();
delay(0);
digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[3], LOW);
digitalWrite(ledPins[4], LOW);
}
}
}/code]