-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodigo parcial
86 lines (78 loc) · 1.98 KB
/
Codigo parcial
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
Punto 4int led_Amarillo = 13;
int led_Azul = 12;
int led_Rojo = 8;
int led_Verde = 2;
const int BOTON = 7;
int val = 0;
int state = 0;
int old_val = 0;
void setup() {
pinMode(led_Amarillo, OUTPUT);
pinMode(led_Azul, OUTPUT);
pinMode(led_Rojo, OUTPUT);
pinMode(led_Verde, OUTPUT);
}
void loop(){
val= digitalRead(BOTON);
if ((val == HIGH) && (old_val == LOW)){
state=1-state;
delay(10);
}
old_val = val;
if (state==1){
digitalWrite(led_Amarillo,HIGH); // encender Amarillo verde
delay(2000); // mantener por 2 segundos
digitalWrite(led_Amarillo,LOW); // apagar LED Amarillo
digitalWrite(led_Azul,HIGH); // encender LED Azul
delay(2000); // mantener por 2 segundos
digitalWrite(led_Azul,LOW); // apagar LED Azul
digitalWrite(led_Rojo,HIGH); // encender LED rojo
delay(2000); // mantener por 2 segundos
digitalWrite(led_Rojo,LOW); // apagar LED rojo
digitalWrite(led_Verde,HIGH); // encender LED Verde
delay(2000); // mantener por 2 segundos
digitalWrite(led_Verde,LOW); // apagar LED Verde
}
}
Punto 5
const int buttonPin = 2;
const int ledPin = 13;
int time=0;
int dato =0;
int buttonState = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
SerialReceive();
if ( (buttonState == HIGH) || ( dato == 1 )) {
time = millis(); // 1000miilis is un second
if(time <= 30000){ // mientras 30 second
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
buttonState == LOW ;
time= 0;
}
}
else if ( (((buttonState == LOW) && ( time <= 30000) )) || ( (dato == 0 ) && ( time <= 30000)) )
{ digitalWrite(ledPin, LOW);
buttonState == LOW ;
time =0;
}
}
void SerialReceive()
{
while(Serial.available())
{
dato = Serial.read();
}