-
Notifications
You must be signed in to change notification settings - Fork 0
/
BikeRxV2.ino
56 lines (45 loc) · 1.58 KB
/
BikeRxV2.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
// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change:
const long interval = 5000; // interval at which to blink (milliseconds)
unsigned long currentMillis = interval + 1;
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
const int realayPin = 2;
void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
Serial.begin(9600);
pinMode(realayPin, OUTPUT);
digitalWrite(realayPin, HIGH); //OFF Relay/Bike
}
void loop()
{
// Set buffer to size of expected message
uint8_t buf[11];
uint8_t buflen = sizeof(buf);
// Check if received packet is correct size
if (rf_driver.recv(buf, &buflen))
{
// Message received with valid checksum
Serial.print("Message Received: ");
Serial.println((char*)buf);
digitalWrite(realayPin, LOW); //OFF Relay/Bike
Serial.println("Bike Running");
// save the last time you blinked the LED
previousMillis = currentMillis;
}
currentMillis = millis(); //Get the current millisecond
if (currentMillis - previousMillis >= interval) { //compare with prev detected millis
// set the LED with the ledState of the variable:
digitalWrite(realayPin, HIGH); //OFF Relay/Bike
Serial.println("Bike OFF");
}
}