Hello Every body,
Here I am stuck again in another problem. I want to have an FM radio channel search or radio station scan utility with Arduino and a TV tuner plus peripheries (audio etc.). I managed to get the scan function to increment; honestly, I got it accidentally, though, I tried to learn from some posts like this one Adding code to fm sweep - #18
but I couldn't.
I didn't know how get the equivalent of the "radio.setFrequency" in my code, I got errors in the IDE. So I gave up.
// scan 88.00 to 108.00 with increments of 0.1
for ( uint32_t chanx100 = 8800 ; chanx100 < 10800 ; chanx100 += 10 ) {
radio.setFrequency( (float)( chanx100 / 100 ) );
delayMicroseconds( 250 ) ; // note:the .cpp file has a delay of 100ms anyway per channel change
}
digitalWrite(led, LOW);
delay( 100 ) ;
}
But that's not the issue now as I have a function that increments and stops(forever!).
I need to resume the search upwards incrementing or downwards decrementing by pressing corresponding buttons.
Lots of thanks in advance!
//11.06.2024
#include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
uint16_t FM = 0; //2890;//2890*3.2/64-37
int upButton = 8;
int downButton = 7;
uint16_t FM_End = 2915;
uint16_t FM_Start = 2500;
byte ZeroChar[8] = {
B00000, B00000, B00000, B00000, B00000, B00000, B00000, B11111
};
byte FirstChar[8] = {
B00000, B00000, B00000, B00000, B00000, B00000, B11111, B11111
};
byte SecondChar[8] = {
B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111
};
byte ThirdChar[8] = {
B00000, B00000, B00000, B00000, B11111, B11111, B11111, B11111
};
byte FourthChar[8] = {
B00000, B00000, B00000, B11111, B11111, B11111, B11111, B11111
};
byte FifthChar[8] = {
B00000, B00000, B11111, B11111, B11111, B11111, B11111, B11111
};
byte SixthChar[8] = {
B00000, B11111, B11111, B11111, B11111, B11111, B11111, B11111
};
byte SeventhChar[8] = {
B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111
};
void setup()
{
Wire.begin();
Wire.beginTransmission(0x61);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.createChar(0, ZeroChar);
lcd.createChar(1, FirstChar);
lcd.createChar(2, SecondChar);
lcd.createChar(3, ThirdChar);
lcd.createChar(4, FourthChar);
lcd.createChar(5, FifthChar);
lcd.createChar(6, SixthChar);
lcd.createChar(7, SeventhChar);
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(A0, INPUT);
delay(200);
lcd.clear();
}
void loop()
{
FM_Band();
RSSI();
}
void FM_Band()
{
Wire.beginTransmission(0x61);
uint16_t fpd = 0;
fpd = (FM + 107);
Wire.write(fpd >> 8); //DB1
Wire.write(fpd & 0xFF); //DB2
Wire.write(0xC0); //CB
Wire.write(0x01); //BB
if (FM <= FM_Start)
{
FM = (FM_Start);
}
else
if (FM >= FM_End)
{
FM = (FM_Start);
}
delay(100);
FM++;
int RSS_IN = analogRead(A0);
RSS_IN = map(RSS_IN, 0, 1023, 0, 8);
if (RSS_IN >= 4)
{
while(1)
{
}
}
lcd.print("RF: MHz");
lcd.setCursor(3, 0);
lcd.print(FM * 3.2 / 64 - 37); //DB1+DB2x32/640-IF
Wire.endTransmission();
Wire.requestFrom(0x61, 1);
if (upButton == 0)
{
FM++;
}
}
void RSSI()
{
int RSS_IN = analogRead(A0);
RSS_IN = map(RSS_IN, 0, 1023, 0, 8);
lcd.setCursor(0, 1);
if (RSS_IN == 0)
{
lcd.setCursor(0, 1);
lcd.print("RSSI: ");
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
}
if (RSS_IN == 1)
{
lcd.setCursor(0, 1);
lcd.print("RSSI: ");
lcd.write((byte)0);
lcd.write((byte)1);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
}
if (RSS_IN == 2)
{
lcd.setCursor(0, 3);
lcd.print("RSSI: ");
lcd.write((byte)0);
lcd.write((byte)1);
lcd.write((byte)2);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
}
if (RSS_IN == 3)
{
lcd.setCursor(0, 3);
lcd.print("RSSI: ");
lcd.write((byte)0);
lcd.write((byte)1);
lcd.write((byte)2);
lcd.write((byte)3);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
}
if (RSS_IN == 4)
{
lcd.setCursor(0, 3);
lcd.print("RSSI: ");
lcd.write((byte)0);
lcd.write((byte)1);
lcd.write((byte)2);
lcd.write((byte)3);
lcd.write((byte)4);
lcd.write((byte)0);
lcd.write((byte)0);
lcd.write((byte)0);
}
if (RSS_IN == 5)
{
lcd.setCursor(0, 3);
lcd.print("RSSI: ");
lcd.write((byte)0);
lcd.write((byte)1);
lcd.write((byte)2);
lcd.write((byte)3);
lcd.write((byte)4);
lcd.write((byte)5);
lcd.write((byte)0);
lcd.write((byte)0);
}
if (RSS_IN == 6)
{
lcd.setCursor(0, 3);
lcd.print("RSSI: ");
lcd.write((byte)0);
lcd.write((byte)1);
lcd.write((byte)2);
lcd.write((byte)3);
lcd.write((byte)4);
lcd.write((byte)5);
lcd.write((byte)6);
lcd.write((byte)0);
}
if (RSS_IN == 7)
{
lcd.setCursor(0, 3);
lcd.print("RSSI: ");
lcd.write((byte)0);
lcd.write((byte)1);
lcd.write((byte)2);
lcd.write((byte)3);
lcd.write((byte)4);
lcd.write((byte)5);
lcd.write((byte)6);
lcd.write((byte)7);
}
}
