/*
O número de bandas é calculado conforme aumentamos Bandas[], Fmin[] e Fmax[]
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define INC 2
#define DEC 3
#define BAND 4
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
String Bandas[] = {"160m", "80m", "40m", "20m", "15m", "10m", "6m", "2m"};
unsigned long Fmin[] = {1800000, 3500000, 7000000, 14000000, 21000000, 28000000, 50000000, 144000000};
unsigned long Fmax[] = {2000000, 4000000, 7300000, 14300000, 21500000, 28300000, 54000000, 148000000};
bool FBAND;
int tec, i;
unsigned long F, STEP;
void setup(){
pinMode(INC, INPUT);
pinMode(DEC, INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Frequencia:");
i = 0;
STEP = 100000;
FBAND = true;
}
void loop(){
lcd.setCursor(11,3);
lcd.print("NBandas:");
lcd.print(sizeof(Bandas)/sizeof(Bandas[0]));
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(Bandas[i]);
if(FBAND){
F = Fmin[i];
FBAND = false;
}
lcd.setCursor(0,2);
lcd.print(" ");
lcd.setCursor(0,2);
lcd.print(F);
lcd.setCursor(0,3);
lcd.print(STEP);
tec = le_teclas();
//Incrementa frequência
if(tec == 1){
F = F + STEP;
if(F > Fmax[i])
F = Fmax[i];
}
//Decrementa frequência
else if(tec == 2){
F = F - STEP;
if(F < Fmin[i])
F = Fmin[i];
}
//Altera banda
else if(tec == 3){
i++;
if(i > (sizeof(Bandas)/sizeof(Bandas[0]))-1)
i = 0;
FBAND = true;
}
}
int le_teclas(void){
int tecla = 0;
do{
if(digitalRead(INC) == 0){
tecla = 1;
}
else if(digitalRead(DEC) == 0){
tecla = 2;
}
else if(digitalRead(BAND) == 0){
tecla = 3;
}
}while(tecla == 0);
delay(400);
return tecla;
}