Salutations! Wondering how to control leds with less code. For the first code, I have 5 led's to create a chase effect. The second, a WS2812B matrix. How can I control all led's at once on the matrix w/o 64 lines of code? Thank you in advance!
int ledPins[] = {5,6,7,8,9};
int pushButton = 4;
void setup() {
int index;
for (index = 0; index <= 5; index++){
pinMode(ledPins, OUTPUT);
pinMode (pushButton, INPUT);
}
}
void loop() {
pushButton = digitalRead(4);
if (pushButton == 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);
}
else {
digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], LOW);
digitalWrite(ledPins[3], LOW);
digitalWrite(ledPins[4], LOW);
}
}/code]
[code]#include <FastLED.h>
#define LED_PIN 7
#define NUM_LEDS 64
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
leds[0] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[1] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[2] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[3] = CRGB(150, 0, 255);
FastLED.show();
delay(500);
leds[4] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[5] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[6] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[7] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[8] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[9] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[10] = CRGB(150, 0, 255);
FastLED.show();
delay(500);
leds[11] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[12] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
leds[13] = CRGB(0, 0, 255);
FastLED.show();
delay(500);
}/code]