-
Notifications
You must be signed in to change notification settings - Fork 0
/
3tasksLED.ino
51 lines (43 loc) · 961 Bytes
/
3tasksLED.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define RED 12
#define YELLOW 10
#define GREEN 11
#define BUTTONPIN 2
#define POTEN A4
int blinkstate = 470;
int LEDSTATE = LOW;
unsigned long timeStart;
void setup() {
timeStart = millis();
Serial.begin(115200);
Serial.setTimeout(10);
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BUTTONPIN, INPUT);
}
void loop() {
unsigned long timeNow = millis();
if (Serial.available() > 0) {
int val = Serial.parseInt();
if (val > 100 && val < 4000) {
blinkstate = val;
}
}
if (timeNow - timeStart > blinkstate) {
if (LEDSTATE == LOW) {
LEDSTATE = HIGH;
} else {
LEDSTATE = LOW;
}
digitalWrite(RED, LEDSTATE);
timeStart = timeNow;
}
if (digitalRead(BUTTONPIN) == HIGH) {
digitalWrite(GREEN, HIGH);
} else {
digitalWrite(GREEN, LOW);
}
int poten = analogRead(POTEN);
int led_brightness = poten / 4;
analogWrite(YELLOW, led_brightness);
}