Change power of the light with potentiometer (better).
This commit is contained in:
+22
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user