//Libraries:
#include <TEA5767.h>
#include <Wire.h>
//Constants:
TEA5767 Radio; //Pinout SLC and SDA - Arduino uno pins A5 and A4
//Variables:
double old_frequency;
double frequency;
int search_mode = 0;
int search_direction;
unsigned long last_pressed;
unsigned char buf[5];
int stereo;
int signal_level;
double current_freq;
unsigned long current_millis = millis();
int inByte;
int flag=0;
void setup () {
//Init
Serial.begin(9600);
Radio.init();
Radio.set_frequency(95.2); //On power on go to station 95.2
lcd.init();
lcd.backlight(); //backlight is now ON
lcd.begin(16,2);
lcd.clear();
}
void loop () {
if (Serial.available()>0) {
inByte = Serial.read();
if (inByte == '+' || inByte == '-'){ //accept only + and - from keyboard
flag=0;
}
}
if (Radio.read_status(buf) == 1) {
current_freq = floor (Radio.frequency_available (buf) / 100000 + .5) / 10;
stereo = Radio.stereo(buf);
signal_level = Radio.signal_level(buf);
//By using flag variable the message will be printed only one time.
if(flag == 0){
Serial.print("Current freq: ");
Serial.print(current_freq);
Serial.print("MHz Signal: ");
//Strereo or mono ?
if (stereo){
Serial.print("STEREO ");
}
else{
Serial.print("MONO ");
}
Serial.print(signal_level);
Serial.println("/15");
flag=1;
}
}
//When button pressed, search for new station
if (search_mode == 1) {
if (Radio.process_search (buf, search_direction) == 1) {
search_mode = 0;
}
}
//If forward button is pressed, go up to next station
if (inByte == '+') {
last_pressed = current_millis;
search_mode = 1;
search_direction = TEA5767_SEARCH_DIR_UP;
Radio.search_up(buf);
}
//If backward button is pressed, go down to next station
if (inByte == '-') {
last_pressed = current_millis;
search_mode = 1;
search_direction = TEA5767_SEARCH_DIR_DOWN;
Radio.search_down(buf);
}
Tried a lot of thing but cant find how to solve the problem