-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFM_Radio.ino
101 lines (86 loc) · 2.22 KB
/
FM_Radio.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
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <AnalogSmooth.h>
#include <TEA5767N.h>
#include <LiquidCrystal.h>
int contrast = 120;
TEA5767N radio = TEA5767N();
int analogPin = 0;
int analogPin2 = 1;
int val = 0;
int frequencyInt = 0;
float frequency = 104.5;
float previousFrequency = 104.5;
AnalogSmooth as = AnalogSmooth(100);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int RECV_PIN = 10;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;
void setup() {
radio.setMonoReception();
radio.setStereoNoiseCancellingOn();
analogWrite(6, contrast);
lcd.begin(16, 2);
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
}
void loop() {
//Commented code is for POTENTIOMETER MODE (DEBUG/LOW REMOTE BATTERY)
//for (int i = 0; i < 30; i++) {
//val = val + as.smooth(analogRead(analogPin));
//delay(1);
//}
if (irrecv.decode(&results)) {
switch (results.value) {
case 0xFFA25D: //Keypad button "2"
frequency = frequency - 0.1;
}
switch (results.value) {
case 0xFFE21D: //Keypad button "2"
frequency = frequency + 0.1;
}
switch (results.value) {
case 0xFF22DD: //Keypad button "2"
frequency = frequency - 1;
}
switch (results.value) {
case 0xFF02FD: //Keypad button "2"
frequency = frequency + 1;
}
irrecv.resume();
}
//val = val / 30;
//frequencyInt = map(val, 2, 1014, 8700, 10700);
//float frequency = frequencyInt / 100.0f;
if (frequency != previousFrequency) {
lcd.clear();
radio.selectFrequency(frequency);
printFrequency(frequency);
previousFrequency = frequency;
}
//lcd.clear();
//printFrequency(frequency);
if (frequency > 104.3 && frequency < 104.7) {
lcd.setCursor(0, 1);
lcd.print("CHUM");
}
if (frequency > 99.8 && frequency < 100.1) {
lcd.setCursor(0, 1);
lcd.print("VIRGIN");
}
if (frequency > 98.0 && frequency < 98.2) {
lcd.setCursor(0, 1);
lcd.print("CHFI");
}
delay(20);
val = 0;
Serial.println(frequency);
}
void printFrequency(float frequency) {
String frequencyString = String(frequency, 1);
lcd.print(frequencyString + " FM");
}