This repository has been archived by the owner on Nov 29, 2022. It is now read-only.
forked from hirikilabs/INTRODUCCION-ARDUINO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ficha2_code2.ino
83 lines (75 loc) · 1.88 KB
/
Ficha2_code2.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
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
//Aquí almacenamos los datos recogidos del LDR:
int valorLDR = 0;
//Decimos que pines vamos a utilizar para LED
int pinLed1 = 12;
int pinLed2 = 11;
int pinLed3 = 10;
int pinLed4 = 9;
int pinLed5 = 8;
//Y que pin para la LDR
int pinLDR = A0;
void setup()
{
//Establecemos como salida los pines para LED
pinMode(pinLed1, OUTPUT);
pinMode(pinLed2, OUTPUT);
pinMode(pinLed3, OUTPUT);
pinMode(pinLed4, OUTPUT);
pinMode(pinLed5, OUTPUT);
//Le decimos que vamos a usar una referencia externa
analogReference(EXTERNAL);
}
void loop()
{
//Guardamos el valor leido en una variable
valorLDR = analogRead(pinLDR);
//Y comenzamos las comparaciones:
if(valorLDR >= 1023)
{
digitalWrite(pinLed1, LOW);
digitalWrite(pinLed2, LOW);
digitalWrite(pinLed3, LOW);
digitalWrite(pinLed4, LOW);
digitalWrite(pinLed5, LOW);
}
else if((valorLDR >= 823) & (valorLDR < 1023))
{
digitalWrite(pinLed1, HIGH);
digitalWrite(pinLed2, LOW);
digitalWrite(pinLed3, LOW);
digitalWrite(pinLed4, LOW);
digitalWrite(pinLed5, LOW);
}
else if((valorLDR >= 623) & (valorLDR < 823))
{
digitalWrite(pinLed1, HIGH);
digitalWrite(pinLed2, HIGH);
digitalWrite(pinLed3, LOW);
digitalWrite(pinLed4, LOW);
digitalWrite(pinLed5, LOW);
}
else if((valorLDR >= 423) & (valorLDR < 623))
{
digitalWrite(pinLed1, HIGH);
digitalWrite(pinLed2, HIGH);
digitalWrite(pinLed3, HIGH);
digitalWrite(pinLed4, LOW);
digitalWrite(pinLed5, LOW);
}
else if((valorLDR >= 223) & (valorLDR < 423))
{
digitalWrite(pinLed1, HIGH);
digitalWrite(pinLed2, HIGH);
digitalWrite(pinLed3, HIGH);
digitalWrite(pinLed4, HIGH);
digitalWrite(pinLed5, LOW);
}
else
{
digitalWrite(pinLed1, HIGH);
digitalWrite(pinLed2, HIGH);
digitalWrite(pinLed3, HIGH);
digitalWrite(pinLed4, HIGH);
digitalWrite(pinLed5, HIGH);
}
}