-
Notifications
You must be signed in to change notification settings - Fork 0
/
DesafioFinalRui.txt
191 lines (132 loc) · 3.23 KB
/
DesafioFinalRui.txt
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include <Adafruit_LiquidCrystal.h>
Adafruit_LiquidCrystal lcd_1(0);
int buttonPin = 7;
int ledPin = 13;
int buttonPin2 = 6;
int ledPin2 = 10;
int LM35 = A1;
int buzzerPin=8;
int ldrPin = A0;
int pwmPin = A2;
int ledPin3 =9;
int pwmnolcd(int pwm){
lcd_1.setCursor(12, 0);
lcd_1.print(pwm);
}
void lerbotaolcd2(int buttonState2){
lcd_1.setCursor(15, 1);
if(buttonState2==HIGH){
lcd_1.print("D");}
else{
lcd_1.print("L");}
}
int funcligaled3(int pwm){
analogWrite(ledPin3,pwm);
}
int funcpwm(){
int valorLido;
valorLido = analogRead(pwmPin);
Serial.println(valorLido);
return valorLido;
}
int funcledldr(int ldrValor){
lcd_1.setCursor(2, 1);
lcd_1.print(ldrValor);
}
void lertemplcd(float temperatura){
lcd_1.setCursor(3, 0);
lcd_1.print(temperatura );
}
void lerbotaolcd1(int buttonState){
lcd_1.setCursor(10, 1);
if(buttonState==HIGH){
lcd_1.print("D");}
else{
lcd_1.print("L");} }
int funcled3(int valorLido){
int pwm;
pwm = map(valorLido, 0, 1023, 0, 255);
return pwm;
}
void funcbuzzer(float temperatura){
if (temperatura >= 30)
tone(buzzerPin, 2000);
else {
noTone(buzzerPin);
}}
int funcaoLerLuz(){
int ldrValor;
ldrValor = analogRead(ldrPin);
Serial.print("Valor LDR:");
Serial.println(ldrValor);
return ldrValor;
}
float funcaoTemp(){
float temperatura;
temperatura = (float(((((analogRead(LM35)*5.0)/1023)*1000)-500)/10));
Serial.print("Temperatura:");
Serial.println(temperatura);
return temperatura;
}
int funcaoBotao1() {
int buttonState;
Serial.println(buttonState);
buttonState = digitalRead(buttonPin);
return buttonState;
}
int funcaoBotao2() {
int buttonState2=0;
Serial.println(buttonState2);
buttonState2 = digitalRead(buttonPin2);
return buttonState2;}
int funcaoBotaoLed1(int buttonState) {
if (buttonState == HIGH) {
digitalWrite(ledPin, LOW);
} else {
digitalWrite(ledPin, HIGH);
}
}
int funcaoBotaoLed2(int buttonState2) {
if (buttonState2 == HIGH) {
digitalWrite(ledPin2, LOW);
} else {
digitalWrite(ledPin2, HIGH);
}}
void setup() {
lcd_1.begin(16, 2);
lcd_1.setCursor(0, 0);
lcd_1.print("TP: PT: ");
lcd_1.setCursor(0, 1);
lcd_1.print("LD L1: L2: ");
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int ldrValor;
unsigned int valorLido;
unsigned int pwm;
int buttonState;
float temperatura;
int buttonState2;
temperatura = funcaoTemp();
funcbuzzer(temperatura);
lertemplcd(temperatura);
buttonState=funcaoBotao1();
funcaoBotaoLed1(buttonState);
lerbotaolcd1(buttonState);
ldrValor=funcaoLerLuz();
funcledldr(ldrValor);
buttonState2=funcaoBotao2();
funcaoBotaoLed2(buttonState2);
lerbotaolcd2(buttonState2);
valorLido = funcpwm();
pwm=funcled3(valorLido);
Serial.println(pwm);
pwmnolcd(pwm);
funcligaled3(pwm);
}