Last active
March 10, 2019 22:47
-
-
Save sapk/a389288dba2500e8b9ca433718999288 to your computer and use it in GitHub Desktop.
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
// Based on NeoPixel Ring simple sketch (c) 2013 Shae Erisson | |
// released under the GPLv3 license | |
#include <Adafruit_NeoPixel.h> | |
// Which pin on the Digispark is connected to the DigiLED? | |
#define PIN 3 | |
// How many DigiLEDs are attached to the Digispark? | |
#define NUMPIXELS 2 | |
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. | |
// For the WS2812B type through hole LED used by the DigiLED, NEO_RGB + NEO_KHZ800 is the correct data format | |
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800); | |
int delayval = 280; // delay | |
bool oldState = LOW; | |
void setup() | |
{ | |
pinMode(0, INPUT); | |
pinMode(1, INPUT); | |
pinMode(2, INPUT); | |
pixels.begin(); // This initializes the NeoPixel library. | |
pixels.show(); // Initialize all pixels to 'off' | |
} | |
void loop() | |
{ | |
if (!digitalRead(0)) { | |
freinage(); | |
} else if (!digitalRead(1) && !digitalRead(2)) { | |
warning(); | |
} else if (!digitalRead(1)) { | |
clignotant_droit(); | |
} else if (!digitalRead(2)) { | |
clignotant_gauche(); | |
}else if (oldState == HIGH) { | |
eteint(); | |
oldState = LOW; | |
} | |
delay(10); | |
} | |
void clign(int pin){ | |
eteint();//Reset | |
if (oldState == LOW) { | |
pixels.setPixelColor(pin, pixels.Color(255, 90, 0)); //orange | |
}else { | |
pixels.setPixelColor(pin, pixels.Color(0, 0, 0)); //black | |
} | |
pixels.show(); | |
delay(delayval); | |
oldState = !oldState; | |
} | |
void clignotant_droit(){ | |
clign(1); | |
} | |
void clignotant_gauche() | |
{ | |
clign(0); | |
} | |
void warning(){ | |
if (oldState == LOW) { | |
pixels.setPixelColor(0, pixels.Color(255, 90, 0)); //orange | |
pixels.setPixelColor(1, pixels.Color(255, 90, 0)); //orange | |
} else { | |
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); //black | |
pixels.setPixelColor(1, pixels.Color(0, 0, 0)); //black | |
} | |
pixels.show(); | |
delay(delayval); | |
oldState = !oldState; | |
} | |
void freinage() | |
{ | |
pixels.setPixelColor(0, pixels.Color(255, 0, 0)); //red | |
pixels.setPixelColor(1, pixels.Color(255, 0, 0)); //red | |
pixels.show(); | |
oldState = HIGH; | |
} | |
void eteint() | |
{ | |
pixels.setPixelColor(0, pixels.Color(0, 0, 0)); //black | |
pixels.setPixelColor(1, pixels.Color(0, 0, 0)); //black | |
pixels.show(); | |
//pixels.clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment