-
Notifications
You must be signed in to change notification settings - Fork 1
/
termoDaQ_firmware_attiny85.ino
92 lines (72 loc) · 1.49 KB
/
termoDaQ_firmware_attiny85.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
84
85
86
87
88
89
90
91
92
#include <avr/io.h>
#include <avr/interrupt.h>
int count = 0;
int t_min = 0;
int potValue = 0;
int intervalValue = 0;
volatile int pcint_value= 1;
#define transistor 0
#define analogIn A1
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
ISR(PCINT0_vect)
{
if(digitalRead(1) == 1){
pcint_value = 0;
}
if(digitalRead(1) == 0){
pcint_value = 1;
}
}
void setup()
{
pinMode(1,INPUT);
pinMode(analogIn, INPUT);
pinMode(transistor, OUTPUT);
sbi(GIMSK,PCIE); // Turn on Pin Change interrupt
sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt
}
void loop()
{
count = count + 1;
potValue = analogRead(analogIn);
intervalValue = map(potValue, 0, 1023, 1, 30);
if(intervalValue <= 2){
intervalValue = 1;
}
if(intervalValue > 2 && intervalValue <= 5){
intervalValue = 5;
}
if(intervalValue > 5 && intervalValue <= 10){
intervalValue = 10;
}
if(intervalValue > 10 && intervalValue <= 15){
intervalValue = 15;
}
if(intervalValue > 15 && intervalValue <= 20){
intervalValue = 20;
}
if(intervalValue > 20 && intervalValue <= 25){
intervalValue = 25;
}
if(intervalValue > 25 && intervalValue <= 30){
intervalValue = 30;
}
if (t_min == intervalValue)
{
digitalWrite(transistor, HIGH);
while(pcint_value){
// espera
}
digitalWrite(transistor, LOW);
pcint_value = 1;
t_min = 0;
}
if (count == 59)
{
count = 0;
t_min = t_min + 1;
}
delay(1000);
}