From b587f812048d9da55c0232b64ba7b2734712c745 Mon Sep 17 00:00:00 2001 From: DoctorPok <58393254+DoctorPok42@users.noreply.github.com> Date: Mon, 3 Jan 2022 12:16:52 +0100 Subject: [PATCH] Update index.ino --- index.ino | 82 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/index.ino b/index.ino index 48b35bc..4da79d6 100644 --- a/index.ino +++ b/index.ino @@ -1,14 +1,13 @@ #include #include "rgb_lcd.h" rgb_lcd lcd; - int R; int G; int B; + void setup() { lcd.begin(16, 2); - lcd.clear(); Serial.begin(9600); } @@ -16,48 +15,53 @@ void loop() { lcd.setRGB(R,G,B); - int Val = analogRead(A3); - - int RGB = map(Val,0,1023,0,100); + int Val = analogRead(A3); + int RGB = map(Val,0,1023, 0,100); // On divise 100 en 6 parties pours correespondre au angles -if(RGB <= 16.6){ // 0 to 60° - R = 100; - G = RGB * 6; - B = 0; -} -if((RGB > 16.6) && (RGB <= 33.3)){ // 60° to 120° - R = 100 - (RGB - 16.6) * 6; - G = 100; - B = 0; -} -if((RGB > 33.3) && (RGB <= 50)){ // 120° to 180° - R = 0; - G = 100; - B = (RGB - 33.3) * 6; -} -if((RGB > 50) && (RGB <= 62.3)){ // 180° to 240° - R = 0; - G = 100 - (RGB - 50) * 6; - B = 100; -} -if((RGB > 66.6) && (RGB <= 83.3)){ // 240° to 300° - R = (RGB - 66.6) * 6; - G = 0; - B = 100; -} -if((RGB > 83.3) && (RGB <= 100)){ // 300° to 360° - R = 100; - G = 0; - B = 100 - (RGB - 86.6) * 6; -} + if(RGB <= 16.6){ // 0 to 60° + R = 100; + G = RGB * 6; + B = 0; + } + + if((RGB > 16.6) && (RGB <= 33.3)){ // 60° to 120° + R = 100 - (RGB - 16.6) * 6; + G = 100; + B = 0; + } + + if((RGB > 33.3) && (RGB <= 50)){ // 120° to 180° + R = 0; + G = 100; + B = (RGB - 33.3) * 6; + } + if((RGB > 50) && (RGB <= 62.3)){ // 180° to 240° + R = 0; + G = 100 - (RGB - 50) * 6; + B = 100; + } + if((RGB > 66.6) && (RGB <= 83.3)){ // 240° to 300° + R = (RGB - 66.6) * 6; + G = 0; + B = 100; + } - lcd.clear(); - lcd.setCursor(0, 0); lcd.print ("Valeur lue: "); lcd.print (Val); - lcd.setCursor(0, 1); lcd.print ("RGB: "); lcd.print (RGB); + if((RGB > 83.3) && (RGB <= 100)){ // 300° to 360° + R = 100; + G = 0; + B = 100 - (RGB - 86.6) * 6; + } + lcd.clear(); + lcd.setCursor(0, 0); lcd.print(" R:"); lcd.print(R); + lcd.print(" G:"); lcd.print(G); + lcd.print(" B:"); lcd.print(B); - delay(125); // attente en 100 ms soit 0.10 secondes + lcd.setCursor(0, 1); lcd.print("HEX : "); lcd.print(R,HEX); + lcd.print(G,HEX); + lcd.print(B,HEX); + delay(100); }