From 666580ecbe3b16eb27544e126a85c6a4a1928a30 Mon Sep 17 00:00:00 2001 From: Chapan Harder Date: Wed, 20 May 2026 23:02:01 +0330 Subject: [PATCH] Change power of the light with potentiometer (better). --- src/main.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6aefc67..1823433 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,18 +1,37 @@ #include -#define LED 6 +#define BLUE_LED 6 +#define YELLOW_LED 5 +#define RED_LED 3 #define ANALOG_A0 A0 int Voltage = 0; // Setup Section void setup() { - pinMode(LED, OUTPUT); + pinMode(BLUE_LED, OUTPUT); + pinMode(YELLOW_LED, OUTPUT); + pinMode(RED_LED, OUTPUT); } // Loop Section void loop() { Voltage = analogRead(ANALOG_A0); Voltage = Voltage / 4; - analogWrite(LED, Voltage); + + if (Voltage > 170 && Voltage <= 255) { + analogWrite(RED_LED, Voltage-170); + analogWrite(YELLOW_LED, 0); + analogWrite(BLUE_LED, 0); + } + else if (Voltage > 85 && Voltage <= 170) { + analogWrite(RED_LED, 0); + analogWrite(YELLOW_LED, Voltage-85); + analogWrite(BLUE_LED, 0); + } + else { + analogWrite(RED_LED, 0); + analogWrite(YELLOW_LED, 0); + analogWrite(BLUE_LED, Voltage); + } }