-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCame_Gates_Control.ino
123 lines (111 loc) · 3.24 KB
/
Came_Gates_Control.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
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
#include <Keypad.h>
//=================================================================================================
#define TX_PIN 11
#define LED_PIN 13
#define BIT_LEN 320
#define BLINK_INTERVAL 500
//=================================================================================================
// Setup Keypad
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {8, 3, 4, 6};
byte colPins[COLS] = {7, 9, 5};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//=================================================================================================
// Defind gate codes
#define GATE_MAIN_IN 0xAAAAAA
#define GATE_MAIN_OUT 0xBBBBBB
#define GATE_PARK_NEAR_IN 0xCCCCCC
#define GATE_PARK_NEAR_OUT 0xDDDDDD
#define GATE_PARK_FAR_IN 0xEEEEEE
#define GATE_PARK_FAR_OUT 0xFFFFFF
//=================================================================================================
// Global variables
unsigned long previousMillis = 0;
int LED_state = LOW;
//=================================================================================================
// Send code vith help of 433 MHz transmitter connected to TX_PIN
void SendCame(unsigned long code)
{
int repeat_count;
repeat_count = 24;
for (int j=0; j<repeat_count; j++)
{
digitalWrite(TX_PIN, LOW);
delayMicroseconds(BIT_LEN * 63);
digitalWrite(TX_PIN, HIGH);
delayMicroseconds(BIT_LEN);
//Sending bit by bit
for (int i=23; i>=0; i--)
{ // 0 -> 011, 1 -> 001
byte b = bitRead(code, i);
digitalWrite(TX_PIN,LOW);
delayMicroseconds(BIT_LEN);
if (!b)
digitalWrite(TX_PIN,HIGH);
delayMicroseconds(BIT_LEN);
digitalWrite(TX_PIN,HIGH);
delayMicroseconds(BIT_LEN);
}
digitalWrite(TX_PIN,LOW);
delay(16);
}
}
//-------------------------------------------------------------------------------------------------
void setup()
{
delay(200);
// Setup outpus for transmitter and LED pins
pinMode(TX_PIN, OUTPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600); // Kept for keypad diagnostics
}
//-------------------------------------------------------------------------------------------------
void loop()
{
unsigned long currentMillis = millis();
char key = keypad.getKey();
if (key)
{
Serial.println(key); // Just for diagnostics
switch (key)
{
case '3':
SendCame(GATE_MAIN_IN);
break;
case '6':
SendCame(GATE_MAIN_OUT);
break;
case '9':
SendCame(GATE_PARK_NEAR_IN);
break;
case '#':
SendCame(GATE_PARK_NEAR_OUT);
break;
case '8':
SendCame(GATE_PARK_FAR_IN);
break;
case '0':
SendCame(GATE_PARK_FAR_OUT);
break;
}
}
// Simply blink LED to show that board is alive
if (currentMillis - previousMillis >= BLINK_INTERVAL)
{
previousMillis = currentMillis;
if (LED_state == LOW)
LED_state = HIGH;
else
LED_state = LOW;
digitalWrite(LED_PIN, LED_state);
}
}
//-------------------------------------------------------------------------------------------------