Created
July 25, 2017 13:42
-
-
Save anonymous/e2cff9ff52289620536af70729992fe9 to your computer and use it in GitHub Desktop.
Tail Light Code - need help to make it not loop the brake part (button 3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 256 // change to the number of LEDs in your strip | |
#define FRAMES_PER_SECOND 120 | |
#define LED_TYPE WS2812B | |
#define BRIGHTNESS 200 | |
#define DIM 10 | |
// constant variables | |
const int buttonPin1 = 5; // the number of the pushbutton pin | |
const int buttonPin2 = 6; | |
const int buttonPin3 = 7; | |
const int buttonPin4 = 10; | |
// variables will change: | |
int buttonState1 = 0; // variable for reading the pushbutton status | |
int buttonState2 = 0; | |
int buttonState3 = 0; | |
int buttonState4 = 0; | |
int oldButtonState3 = 0; | |
// this creates an LED array to hold the values for each led in your strip | |
CRGB leds[NUM_LEDS]; | |
void setup() | |
{ | |
delay(3000); // 3 second delay for recovery | |
// tell FastLED about the LED strip configuration | |
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds,NUM_LEDS).setCorrection(TypicalLEDStrip); | |
// the wiki features a much more basic setup line: | |
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); | |
Serial.begin(9600); | |
// initialize the pushbutton pin as an input: | |
pinMode(buttonPin1, INPUT); | |
// set master brightness control | |
FastLED.setBrightness(BRIGHTNESS); | |
} | |
void loop() | |
{ | |
// read the state of the pushbutton value: | |
buttonState1 = digitalRead(buttonPin1); | |
buttonState2 = digitalRead(buttonPin2); | |
buttonState3 = digitalRead(buttonPin3); | |
buttonState4 = digitalRead(buttonPin4); | |
// check if the pushbutton is pressed. | |
// if it is, the buttonState is HIGH: | |
if (buttonState1 == HIGH) { | |
//LEFT TURN SIGNAL | |
FastLED.setBrightness(BRIGHTNESS); | |
// left tail light black | |
for (int f = 192; f <= 255; f++) | |
leds[f] = CRGB::Black; | |
// Set the first led back to black | |
for (int a = 192; a <= 220; a++) | |
leds[a] = CRGB::Black; | |
FastLED.show(); | |
delay(200); | |
// FIRST ARROW RED | |
byte firstArrow20[] = | |
{192,193,194,195,196,197,198,199,201,202,203,204,205,206,210,211,212,213,219,220}; | |
for (int g = 0; g<20; g++) { | |
leds[firstArrow20[g]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// FIRST ARROW BLACK | |
for (int g = 0; g<20; g++) { | |
leds[firstArrow20[g]] = CRGB::Black; | |
} | |
FastLED.show(); | |
delay (30); | |
// SECOND ARROW RED | |
byte secondArrow8[] = {207,209,221,227,228,218,214,200}; | |
for (int h = 0; h<8; h++) { | |
leds[secondArrow8[h]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// SECOND ARROW BLACK | |
for (int h = 0; h<8; h++) { | |
leds[secondArrow8[h]] = CRGB::Black; | |
} | |
FastLED.show(); | |
delay (30); | |
// THIRD ARROW RED | |
byte thirdArrow8[] = {208,222,226,236,235,229,217,215}; | |
for (int k = 0; k<8; k++) { | |
leds[thirdArrow8[k]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// THIRD ARROW BLACK | |
for (int k = 0; k<8; k++) { | |
leds[thirdArrow8[k]] = CRGB::Black; | |
} | |
FastLED.show(); | |
delay (30); | |
// FOURTH ARROW RED | |
byte fourthArrow8[] = {223,225,237,243,244,234,230,216}; | |
for (int l = 0; l<8; l++) { | |
leds[fourthArrow8[l]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// FOURTH ARROW BLACK | |
for (int l = 0; l<8; l++) { | |
leds[fourthArrow8[l]] = CRGB::Black; | |
} | |
FastLED.show(); | |
delay (30); | |
// FIFTH ARROW RED | |
byte fifthArrow8[] = {224,238,242,252,251,245,233,231}; | |
for (int m = 0; m<8; m++) { | |
leds[fifthArrow8[m]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// FIFTH ARROW BLACK | |
for (int m = 0; m<8; m++) { | |
leds[fifthArrow8[m]] = CRGB::Black; | |
} | |
FastLED.show(); | |
delay (30); | |
} | |
// RIGHT TURN SIGNAL | |
if (buttonState2 == HIGH) { | |
FastLED.setBrightness(BRIGHTNESS); | |
// Set the first led back to black for 1 second | |
for (int i = 0; i <= 63; i++) | |
leds[i] = CRGB::Black; | |
FastLED.show(); | |
delay(30); | |
// SIXTH ARROW RED | |
byte sixthArrow20[] = | |
{56,57,58,59,60,61,62,63,49,50,51,52,53,54,42,43,44,45,35,36}; | |
for (int n = 0; n<20; n++) { | |
leds[sixthArrow20[n]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// SIXTH ARROW BLACK | |
for (int n = 0; n<20; n++) { | |
leds[sixthArrow20[n]] = CRGB::Black; | |
} | |
FastLED.show(); | |
delay (30); | |
// SEVENTH ARROW RED | |
byte seventhArrow8[] = {48,55,46,41,37,34,28,27}; | |
for (int o = 0; o<8; o++) { | |
leds[seventhArrow8[o]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// SEVENTH ARROW BLACK | |
for (int o = 0; o<8; o++) { | |
leds[seventhArrow8[o]] = CRGB::Black; | |
} | |
FastLED.show(); | |
delay (30); | |
// EIGTH ARROW RED | |
byte eigthArrow8[] = {47,40,33,38,26,29,19,20}; | |
for (int p = 0; p<8; p++) { | |
leds[eigthArrow8[p]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// EIGHT ARROW BLACK | |
for (int p = 0; p<8; p++) { | |
leds[eigthArrow8[p]] = CRGB::Black; | |
} | |
FastLED.show(); | |
delay (30); | |
// NINTH ARROW RED | |
byte ninthArrow8[] = {39,32,25,30,21,18,12,11}; | |
for (int q = 0; q<8; q++) { | |
leds[ninthArrow8[q]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// NINTH ARROW BLACK | |
for (int q = 0; q<8; q++) { | |
leds[ninthArrow8[q]] = CRGB::Black; | |
} | |
FastLED.show(); | |
delay (30); | |
// TENTH ARROW RED | |
byte tenthArrow8[] = {31,24,22,17,13,10,4,3}; | |
for (int r = 0; r<8; r++) { | |
leds[tenthArrow8[r]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay (100); | |
// TENTH ARROW BLACK | |
for (int r = 0; r<8; r++) { | |
leds[tenthArrow8[r]] = CRGB::Black; | |
} | |
delay (30); | |
} | |
//BRAKE LIGHT | |
FastLED.setBrightness(BRIGHTNESS); | |
if(buttonState3 == HIGH){ | |
// Set the right tail light black | |
for (int i = 0; i <= 63; i++) | |
leds[i] = CRGB::Black; | |
// left tail light black | |
for (int j = 192; j <= 255; j++) | |
leds[j] = CRGB::Black; | |
//CENTER 4 | |
byte center4[] = {36,35,28,27,227,228,219,220}; | |
for (int b = 0; b<8; b++) { | |
leds[center4[b]] = CRGB::Blue; | |
} | |
FastLED.show(); | |
delay(200); | |
// FIRST RING | |
byte firstRing12[] = | |
{42,43,44,45,37,29,21,20,19,18,26,34,234,235,236,237,226,221,210,211,212,213,218,229}; | |
for (int c = 0; c<24; c++) { | |
leds[firstRing12[c]] = CRGB::Red; | |
} | |
FastLED.show(); | |
delay(200); | |
// SECOND RING | |
byte secondRing20[] = | |
{49,50,51,52,53,46,38,30,22,14,13,12,11,10,9,17,25,33,41,54,241,242,243,244,245,246,233,230,217,214,201,202,203,204,205,206,209,222,225,238}; | |
for (int d = 0; d<40; d++) { | |
leds[secondRing20[d]] = CRGB::Red; | |
} | |
delay (200); | |
// THIRD RING | |
byte thirdRing28[] = | |
{63,62,61,60,59,58,57,56,55,47,39,31,23,15,7,6,5,4,3,2,1,0,8,16,24,32,40,48,255,254,253,252,251,250,249,248,247,232,231,216, | |
215,200,199,198,197,196,195,194,193,192,207,208,223,224,239,240}; | |
for (int e = 0; e<56; e++) { | |
leds[thirdRing28[e]] = CRGB::Red; | |
} | |
delay(200); | |
oldButtonState3 = HIGH; // so this block can only run once | |
} | |
// "stop braking" code here | |
// turn LED off: | |
if(buttonState3 == LOW && oldButtonState3 == HIGH) { | |
FastLED.setBrightness(DIM); | |
// Set the right tail light to black for 1 second | |
for (int i = 0; i <= 63; i++) | |
leds[i] = CRGB::Red; | |
// Set the left tail light to black for 1 second | |
for (int j = 192; j <= 255; j++) | |
leds[j] = CRGB::Red; | |
FastLED.show(); | |
oldButtonState3 == LOW; | |
FastLED.setBrightness(BRIGHTNESS); | |
} | |
if (buttonState4 == HIGH) { | |
//// Set the right tail light to black for 1 second | |
for (int i = 0; i <= 63; i++) | |
leds[i] = CRGB::Red; | |
// Set the left tail light to black for 1 second | |
for (int j = 192; j <= 255; j++) | |
leds[j] = CRGB::Blue; | |
FastLED.show(); | |
delay (100); | |
// Set the right tail light to black for 1 second | |
for (int i = 0; i <= 63; i++) | |
leds[i] = CRGB::Blue; | |
// Set the left tail light to black for 1 second | |
for (int j = 192; j <= 255; j++) | |
leds[j] = CRGB::Red; | |
FastLED.show(); | |
delay (100) ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment