-
Notifications
You must be signed in to change notification settings - Fork 0
/
Transmitter.ino
57 lines (57 loc) · 1.26 KB
/
Transmitter.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
volatile int flow_frequency;
float vol = 0.0, l_minute;
unsigned char flowsensor = 2;
unsigned long currentTime;
unsigned long cloopTime;
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK rf_driver;
int i=0;
void flow ()
{
flow_frequency++;
}
void setup()
{
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(flowsensor), flow, RISING);
currentTime = millis();
cloopTime = currentTime;
rf_driver.init();
}
void loop ()
{
currentTime = millis();
if(currentTime >= (cloopTime + 1000))
{
cloopTime = currentTime;
if(flow_frequency != 0){
l_minute = (flow_frequency / 7.5);
l_minute = l_minute/60;
vol = vol +l_minute;
Serial.print("Vol:");
Serial.print(vol);
Serial.print(" L");
Serial.println("");
flow_frequency = 0;
}
else {
Serial.print("Vol:");
Serial.print(vol);
Serial.print(" L");
Serial.println("");
}
i+=1;
if (i>=60){
i=0;
String str_out=String(vol);
static char *msg = str_out.c_str();
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
vol=0;
delay(1000);
}
}
}