Hi all,
I'm Jason and I am new to all this so please go easy on me. I am trying to make an array of LED's to replicate the indicators of a new Audi. I have put some code together out of examples on here and other sources.
I have sorted the sweep, and the colour, and I have 2 arrays one for the left and one for the right both operating from there own input. the problem Ihave is I need to activate both at the same time to indicate the Hazard warning lights.
Could any of you nice people have a solution to drive both arrays at the same time.
the LED arrays are WS2812b RGB strips.
here is the code.
Thanks
Jason.
//$ cd ~/Arduino/libraries
//$ git clone GitHub - FastLED/FastLED: The FastLED library for colored LED animation on Arduino. Please direct questions/requests for help to the FastLED Reddit community: http://fastled.io/r We'd like to use github "issues" just for tracking library bugs / enhancements.
//Now you can create a new .ino file with your IDE of choice (I've really been loving Sublime Text) and insert the starter code from the FastLED wiki:
#include "FastLED.h"
// fast led constants
#define DATA_PIN 3 // change to your data pin
#define COLOR_ORDER GRB // if colors are mismatched; change this
#define NUM_LEDS 20 // change to the number of LEDs in your strip
#define DATA_PIN1 5 // change to your data pin
#define COLOR_ORDER GRB // if colors are mismatched; change this
#define NUM_LEDS1 20// change to the number of LEDs in your strip
#define IN_1 10
#define IN_2 12
// change WS2812B to match your type of LED, if different
// list of supported types is here:
// Overview · FastLED/FastLED Wiki · GitHub
#define LED_TYPE WS2812B
int IN_4 = 4; // set up input 4
int IN_6 = 6; // set up input 6
int IN_7 = 7; // set up input 6
// this creates an LED array to hold the values for each led in your strip
CRGB leds[NUM_LEDS]; // Array 1
CRGB leds1[NUM_LEDS1]; // Array 2
// This sets up the Colour pallet
DEFINE_GRADIENT_PALETTE( heatmap_gp ) {
0, 0, 0, 0, //black
128, 255, 0, 0, //red
224, 255,255, 0, //bright yellow
255, 255,255,255 }; //full white
CRGBPalette16 myPal = heatmap_gp;
uint8_t heatindex = (156);
void setup()
{
// the wiki features a much more basic setup line:
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.addLeds<LED_TYPE, DATA_PIN1, COLOR_ORDER>(leds1, NUM_LEDS1);
pinMode(IN_4,INPUT);
pinMode(IN_6,INPUT);
pinMode(IN_7,INPUT);
pinMode(IN_1,OUTPUT);
pinMode(IN_2,OUTPUT);
reset_ports();
}
void blink_left(int port) // Left indicator sequence
{
for(int dot = 0; dot < NUM_LEDS; dot++)
{
leds[dot] = ColorFromPalette( myPal, heatindex); // normal palette access
FastLED.show();
delay(25);
}
delay(200);
for(int dot = 0; dot < NUM_LEDS; dot++)
{
leds[dot] = CRGB::Black;
FastLED.show();
// clear this led for the next time around the loop
leds[NUM_LEDS - dot] = CRGB::Black;
delay(1);
}
delay(200);
}
void blink_right(int port) // Right indicator sequence
{
for(int dot1 = 0; dot1 < NUM_LEDS1; dot1++)
{
leds1[dot1] = ColorFromPalette( myPal, heatindex); // normal palette access
FastLED.show();
delay(25);
}
delay(200);
for(int dot1 = 0; dot1 < NUM_LEDS1; dot1++)
{
leds1[dot1] = CRGB::Black;
FastLED.show();
// clear this led for the next time around the loop
leds1[NUM_LEDS1 - dot1] = CRGB::Black;
delay(1);
}
delay(200);
}
void reset_ports()
{
digitalWrite(IN_1,0);
digitalWrite(IN_2,0);
}
void loop()
{
IN_4 = digitalRead(4);
if (IN_4 == HIGH){
blink_left(IN_2);
reset_ports();
}
IN_6 = digitalRead(6);
if (IN_6 == HIGH){
blink_right(IN_2);
reset_ports();
}
IN_7 = digitalRead(7);
if (IN_7 == HIGH){
// blink_both(IN_2);
reset_ports();
}
}