-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_vhf_atmega2560.ino
executable file
·410 lines (369 loc) · 10.8 KB
/
control_vhf_atmega2560.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/*##############################################################################
# PROJECT : Control VHF (KTR 905 COMM TRANSCEIVER)
# AUTHOR : Moschogiannis Paschalis
# FILENAME : control_vhf_atmega2560.ino
#
#
# This file is part of the Control VHF project. More information about
# this project can be found here: [email protected]
################################################################################
*/
//We always have to include the library
#include "LedControl.h"
#include <Keypad.h>
#include <math.h>
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
//connect to the row pinouts of the keypad
byte rowPins[ROWS] = {53, 52, 51, 50};
//connect to the column pinouts of the keypad
byte colPins[COLS] = {49, 48, 47, 46};
//initialize an instance of class NewKeypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int keyNum = 0;
/*
Now we need a LedControl to work with.
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=500;
/*Variable welcome used to show "Hello... ----- 12345678" one time.*/
int welcome=0;
int i=5;
int z=0;
int wire=22;
int dec[5];
String bcd;
int digit;
int dec_counter=0;
int bcd_counter=0;
void setup() {
/*
* The MAX72XX is in power-saving mode on startup,
* we have to do a wakeup call
*/
/*
* Set the shutdown (power saving) mode for the device
* Params :
* addr The address of the display to control
* status If true the device goes into power-down mode. Set to false
* for normal operation.
*/
lc.shutdown(0,false);
/*
* Set the brightness of the display.
* Params:
* addr the address of the display to control
* intensity the brightness of the display. (0..15)
*/
lc.setIntensity(0,4);
/*
* Switch all Leds on the display off.
* Params:
* addr address of the display to control
*/
lc.clearDisplay(0);
Serial.begin(9600);
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
pinMode(24, OUTPUT);
pinMode(25, OUTPUT);
pinMode(26, OUTPUT);
pinMode(27, OUTPUT);
pinMode(28, OUTPUT);
pinMode(29, OUTPUT);
pinMode(30, OUTPUT);
pinMode(31, OUTPUT);
pinMode(32, OUTPUT);
pinMode(33, OUTPUT);
pinMode(34, OUTPUT);
pinMode(35, OUTPUT);
pinMode(36, OUTPUT);
pinMode(37, OUTPUT);
}
void hello(){
/*
* Display a character on a 7-Segment display.
* There are only a few characters that make sense here :
* '0','1','2','3','4','5','6','7','8','9','0',
* 'A','b','c','d','E','F','H','L','P',
* '.','-','_',' '
* Params:
* addr address of the display
* digit the position of the character on the display (0..7)
* value the character to be displayed.
* dp sets the decimal point.
*/
lc.setChar(0,7,'H',false);
lc.setChar(0,6,'E',false);
lc.setChar(0,5,'L',false);
lc.setChar(0,4,'L',false);
lc.setChar(0,3,'0',false);
lc.setChar(0,2,'.',false);
lc.setChar(0,1,'.',false);
lc.setChar(0,0,'.',false);
delay(delaytime+1000);
lc.clearDisplay(0);
for(int k=0; k<=7; k++) {
lc.setChar(0,k,'-',false);
}
delay(delaytime+1000);
lc.clearDisplay(0);
int l=1;
for(int k=7; k>=0; k--) {
lc.setDigit(0,k,l,false);
delay(delaytime);
l++;
}
lc.clearDisplay(0);
//Default frequency
lc.setChar(0,7,'-',false);
lc.setDigit(0,6,1,false);
lc.setChar(0,0,'-',false);
}
int power(int base, int exponent){
long long result = 1;
while (exponent != 0) {
result *= base;
--exponent;
}
return result;
}
String digitToBcd(int digit){
String str="";
for(int n=3; n>=0; n--){
int d = power(2,n);
if(digit/d!=0){
str+="1";
digit-=d;
}
else
str+="0";
}
return str;
}
void loop() {
if (welcome==0) {
hello();
welcome=1;
}
/*
* Set the status of a single Led.
* Params :
* addr address of the display
* row the row of the Led (0..7)
* col the column of the Led (0..7)
* state If true the led is switched on,
* if false it is switched off
*/
lc.setLed(0,4,0,true); //set led of dot pin on
char key = keypad.getKey();
if(key) {
if(key=='*'){
/*
int decimal = 0;
for (int z = 0; z < 5; z++) {
int num = dec[z];
if (num != 0) {
while (num > 0) {
decimal *= 10;
num /= 10;
}
decimal += dec[z];
}else{
decimal *= 10;
}
}
*/
int a;
long decimal=0;
for(a=0; a<5; a++) {
decimal=10*decimal+dec[a];
}
Serial.print("Decimal number:");
Serial.println(decimal);
String bcd="";
while(decimal!=0) {
digit=decimal%10;
bcd=digitToBcd(digit)+bcd;
decimal/=10;
}
Serial.print("BCD number:");
Serial.println(bcd);
for(int bcd_counter=2; bcd_counter<=20; bcd_counter++) {
if(bcd[bcd_counter]=='1') {
digitalWrite(wire, HIGH);
}
else if(bcd[bcd_counter]=='0') {
digitalWrite(wire, LOW);
}
wire++;
}
wire=22;
int i=5;
int z=0;
}
else if(key=='A'){
//Show the frequency A=132.725MHz
lc.setChar(0,7,'-',false);
lc.setDigit(0,6,1,false);
lc.setDigit(0,5,2,false);
lc.setDigit(0,4,1,false);
lc.setDigit(0,3,5,false);
lc.setDigit(0,2,0,false);
lc.setDigit(0,1,0,false);
lc.setChar(0,0,'-',false);
long decimal=21500;
while(decimal!=0) {
digit=decimal%10;
bcd=digitToBcd(digit)+bcd;
decimal/=10;
}
Serial.println(decimal);
Serial.println(bcd);
for(int bcd_counter=2; bcd_counter<=20; bcd_counter++) {
if(bcd[bcd_counter]=='1') {
digitalWrite(wire, HIGH);
}
else if(bcd[bcd_counter]=='0') {
digitalWrite(wire, LOW);
}
wire++;
}
wire=22;
String bcd="";
}
else if(key=='B') {
//Show the frequency B=130.600MHz
lc.setChar(0,7,'-',false);
lc.setDigit(0,6,1,false);
lc.setDigit(0,5,2,false);
lc.setDigit(0,4,2,false);
lc.setDigit(0,3,1,false);
lc.setDigit(0,2,0,false);
lc.setDigit(0,1,0,false);
lc.setChar(0,0,'-',false);
long decimal=22100;
while(decimal!=0) {
digit=decimal%10;
bcd=digitToBcd(digit)+bcd;
decimal/=10;
}
Serial.println(decimal);
Serial.println(bcd);
for(int bcd_counter=2; bcd_counter<=20; bcd_counter++) {
if(bcd[bcd_counter]=='1') {
digitalWrite(wire, HIGH);
}
else if(bcd[bcd_counter]=='0') {
digitalWrite(wire, LOW);
}
wire++;
}
wire=22;
String bcd="";
}
else if(key=='C') {
//Show the frequency C=123.500MHz
lc.setChar(0,7,'-',false);
lc.setDigit(0,6,1,false);
lc.setDigit(0,5,2,false);
lc.setDigit(0,4,9,false);
lc.setDigit(0,3,8,false);
lc.setDigit(0,2,0,false);
lc.setDigit(0,1,0,false);
lc.setChar(0,0,'-',false);
long decimal=29800;
while(decimal!=0) {
digit=decimal%10;
bcd=digitToBcd(digit)+bcd;
decimal/=10;
}
Serial.println(decimal);
Serial.println(bcd);
for(int bcd_counter=2; bcd_counter<=20; bcd_counter++) {
if(bcd[bcd_counter]=='1') {
digitalWrite(wire, HIGH);
}
else if(bcd[bcd_counter]=='0') {
digitalWrite(wire, LOW);
}
wire++;
}
wire=22;
String bcd="";
}
else if(key=='D') {
//Show the frequency D=133.000MHz
lc.setChar(0,7,'-',false);
lc.setDigit(0,6,1,false);
lc.setDigit(0,5,3,false);
lc.setDigit(0,4,2,false);
lc.setDigit(0,3,7,false);
lc.setDigit(0,2,2,false);
lc.setDigit(0,1,5,false);
lc.setChar(0,0,'-',false);
long decimal=32725;
Serial.println(decimal);
while(decimal!=0) {
digit=decimal%10;
bcd=digitToBcd(digit)+bcd;
decimal/=10;
}
Serial.println(bcd);
for(int bcd_counter=2; bcd_counter<=20; bcd_counter++) {
if(bcd[bcd_counter]=='1') {
digitalWrite(wire, HIGH);
}
else if(bcd[bcd_counter]=='0') {
digitalWrite(wire, LOW);
}
wire++;
}
wire=22;
String bcd="";
}
else if(key=='#') {
lc.clearDisplay(0);
//Default frequency
lc.setChar(0,7,'-',false);
lc.setDigit(0,6,1,false);
lc.setChar(0,0,'-',false);
wire=22;
String bcd="";
i=5;
z=0;
}
else{
//convert keypad button to display integer number
if(keyNum<=999) {
keyNum = (keyNum*10) + (int(key)-48);
}
if (key) {
Serial.print("The button that you have pressed:");
Serial.println(key);
}
Serial.print("The KeyNum:");
Serial.println(keyNum);
dec[z]=keyNum;
//display frequency between -132.725-
while(i>=1) {
lc.setDigit(0,i,keyNum,false);
break;
}
z = z + 1;
i = i - 1;
keyNum = 0;
}
}
}