Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Code d'exemple pour une LED RGB (+16 millions de couleurs).
- */
- /* Broches */
- const byte PIN_LED_R = 9;
- const byte PIN_LED_G = 10;
- const byte PIN_LED_B = 11;
- /* Variables */
- int i = 0;
- int r = 0;
- int g = 0;
- int b = 0;
- // Fonction setup(), appelée au démarrage de la carte Arduino
- void setup() {
- // Initialise les broches
- pinMode(PIN_LED_R, OUTPUT);
- pinMode(PIN_LED_G, OUTPUT);
- pinMode(PIN_LED_B, OUTPUT);
- displayColor(0, 0, 0);
- }
- // Fonction loop(), appelée continuellement en boucle tant que la carte Arduino est alimentée
- void loop() {
- String temperature = "chaud";
- upLight(temperature);
- downLight(temperature);
- }
- void upLight(String temperature) {
- while(i<20) {
- displayColor(r,g,b);
- if (temperature == "chaud") {
- r++;
- g++;
- b = 0;
- } else if (temperature == "froid") {
- r = 0;
- g++;
- b++;
- }
- i++;
- delay(50);
- }
- downLight(temperature);
- }
- void downLight(String temperature) {
- while(i>2) {
- displayColor(r,g,b);
- if (temperature == "chaud") {
- r--;
- g--;
- } else if (temperature == "froid") {
- g--;
- b--;
- }
- i--;
- delay(50);
- }
- upLight(temperature);
- }
- /** Affiche une couleur */
- void displayColor(byte r, byte g, byte b) {
- // Assigne l'état des broches
- // Version cathode commune
- analogWrite(PIN_LED_R, r);
- analogWrite(PIN_LED_G, g);
- analogWrite(PIN_LED_B, b);
- // Version anode commune
- //analogWrite(PIN_LED_R, ~r);
- //analogWrite(PIN_LED_G, ~g);
- //analogWrite(PIN_LED_B, ~b);
- }
Add Comment
Please, Sign In to add comment