Change power of the light with potentiometer (better).

This commit is contained in:
2026-05-20 23:02:01 +03:30
parent 1e8773a506
commit 666580ecbe
+22 -3
View File
@@ -1,18 +1,37 @@
#include <Arduino.h>
#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);
}
}