Created
August 3, 2020 14:31
-
-
Save Franck1333/43f8b92ca7a97c75f63e96b57c183992 to your computer and use it in GitHub Desktop.
Petit jeux de lumières avec LED sur une carte Arduino.
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
const int GroupeLED1 = 5; //Composition LED: 1 et 3. | |
const int GroupeLED2 = 6; //Composition LED: 2 et 4. | |
int luminosite = 0; //Luminositee des LEDs. | |
int degraderNB = 5; //Nombre de degrader des LEDs. | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
//---INIT_PIN--- | |
pinMode(GroupeLED1, OUTPUT); //Initialisation du Groupement de LEDs 1 | |
pinMode(GroupeLED2, OUTPUT); //Initialisation du Groupement de LEDs 2 | |
//---INIT_PIN--- | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
//LED_bargraph(512); | |
LED_Respiration(); | |
} | |
void LED_Allumer(void){ | |
//Fonction permettant d'allumer les LEDs saisies. | |
digitalWrite(GroupeLED1, HIGH); //GroupeLED1 ON | |
digitalWrite(GroupeLED2, HIGH); //GroupeLED2 ON | |
} | |
void LED_Eteint(void){ | |
//Fonction permettant d'éteindre les LEDs saisies. | |
digitalWrite(GroupeLED1, LOW); //GroupeLED1 OFF | |
digitalWrite(GroupeLED2, LOW); //GroupeLED2 OFF | |
} | |
void LED_toutes(int duree){ | |
//Fonction permettant d'allumer/eteindre les LEDS saisies. | |
digitalWrite(GroupeLED1, HIGH);//GroupeLED1 ON | |
digitalWrite(GroupeLED2, HIGH);//GroupeLED2 ON | |
delay(duree); | |
digitalWrite(GroupeLED1, LOW); //GroupeLED1 OFF | |
digitalWrite(GroupeLED2, LOW); //GroupeLED2 OFF | |
} | |
void LED_bargraph(int choix){ | |
//Fonction permettant d'utiliser les LEDs d'une facon differente. | |
digitalWrite(GroupeLED1, HIGH);//GroupeLED1 ON | |
delay(choix); | |
digitalWrite(GroupeLED2, HIGH);//GroupeLED2 ON | |
delay(choix); | |
digitalWrite(GroupeLED1, LOW); //GroupeLED1 OFF | |
delay(choix); | |
digitalWrite(GroupeLED2, LOW); //GroupeLED2 OFF | |
delay(choix); | |
} | |
void LED_Respiration(void){ | |
//Effet Respiration sur les LEDs | |
//Aide: https://www.arduino.cc/en/tutorial/fade | |
analogWrite(GroupeLED1, luminosite); | |
analogWrite(GroupeLED2, luminosite); | |
// change the brightness for next time through the loop: | |
luminosite = luminosite + degraderNB; | |
// reverse the direction of the fading at the ends of the fade: | |
if (luminosite <= 0 || luminosite >= 164) { | |
degraderNB = -degraderNB; | |
} | |
// wait for 30 milliseconds to see the dimming effect | |
delay(32); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment