-
Notifications
You must be signed in to change notification settings - Fork 0
/
tarefa2.c
51 lines (40 loc) · 1.05 KB
/
tarefa2.c
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 LED_PIN 13
#define BUT_UP_PIN 2
#define BUT_DOWN_PIN 3
int led_state = 0;
int led_time = 0;
unsigned long b1_last = 0;
unsigned long b2_last = 0;
int intervalo = 1000;
void setup() {
// put your setup code here, to run once:
pinMode(LED_PIN, OUTPUT);
pinMode(BUT_UP_PIN, INPUT);
pinMode(BUT_DOWN_PIN, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int but1 = digitalRead(BUT_UP_PIN);
int but2 = digitalRead(BUT_DOWN_PIN);
// Para caso os dois botões sejam apertados ao mesmo tempo
if (but1 && but2 ) {
digitalWrite(13,LOW);
while(1);
}
// Botão 1 aumenta a velocidade
if (but1 && millis() - b1_last > 250){
b1_last = millis();
intervalo /= 2;
}
// Botão 2 diminui a velocidade
if (but2 && millis() - b2_last > 250){
b2_last = millis();
intervalo *= 2;
}
// Pisca o LED de acordo com o intervalo pre determinado
if( millis() - led_time >= intervalo ) {
led_time = millis();
digitalWrite(LED_PIN, led_state);
led_state = !led_state;
}
}