Dziś krótko, stworzyłem ala radio z wyświetlaczem i pamięcią.
Kod 1 - Wersja finalna działają buttony , wgrane najpopularniejsze stacje , brak jednoczesnej obsługi potenciometru ;C
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
#include <Wire.h>
#include <TEA5767Radio.h>
TEA5767Radio radio = TEA5767Radio();
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
void setup()
{
Wire.begin();
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("R.Kasprzak 2000"); // print a simple message
}
void loop()
{
lcd.setCursor(0,1); // move to the begining of the second line
lcd_key = read_LCD_buttons();
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
radio.setFrequency(104.4);
lcd.print("Stacja VOX FM ");
break;
}
case btnLEFT:
{
radio.setFrequency(107.5);
lcd.print("Stacja RadioZET");
break;
}
case btnUP:
{
radio.setFrequency(92.4);
lcd.print("Stacja Pol.1 ");
break;
}
case btnDOWN:
{
radio.setFrequency(104.9);
lcd.print("Stacja Pol.2 ");
break;
}
case btnSELECT:
{
radio.setFrequency(104.4);
lcd.print("VOX FM ");
break;
}
}
}
Kod 2 działa potenciometr ale kłóci się z buttonami.
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
#include <Wire.h>
#include <TEA5767Radio.h>
TEA5767Radio radio = TEA5767Radio();
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
unsigned char frequencyH = 0;
unsigned char frequencyL = 0;
unsigned int frequencyB;
double frequency = 0;
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
void setup()
{
Wire.begin();
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("R.Kasprzak 2000"); // print a simple message
frequency = 93.0; //starting frequency
setFrequency();
Serial.begin(9600);
}
void loop()
{
lcd.setCursor(0,1); // move to the begining of the second line
lcd_key = read_LCD_buttons();
switch (lcd_key) // depending on which button was pushed, we perform an action
{
case btnRIGHT:
{
radio.setFrequency(104.4);
lcd.print("Stacja VOX FM ");
break;
}
case btnLEFT:
{
radio.setFrequency(107.5);
lcd.print("Stacja RadioZET");
break;
}
case btnUP:
{
radio.setFrequency(92.4);
lcd.print("Stacja Pol.1 ");
break;
}
case btnDOWN:
{
radio.setFrequency(104.9);
lcd.print("Stacja Pol.2 ");
break;
}
case btnSELECT:
{
radio.setFrequency(104.4);
lcd.print("VOX FM ");
break;
}
case btnNONE:
{
int reading = analogRead(7);
//frequency = map((float)reading, 0.0, 1024.0, 87.5, 108.0);
frequency = ((double)reading * (108.0 - 87.5)) / 1024.0 + 87.5;
frequency = ((int)(frequency * 10)) / 10.0;
setFrequency();
Serial.println(frequency);
break;
}
}
}
void setFrequency()
{
frequencyB = 4 * (frequency * 1000000 + 225000) / 32768;
frequencyH = frequencyB >> 8;
frequencyL = frequencyB & 0XFF;
delay(100);
Wire.beginTransmission(0x60);
Wire.write(frequencyH);
Wire.write(frequencyL);
Wire.write(0xB0);
Wire.write(0x10);
Wire.write((byte)0x00);
Wire.endTransmission();
delay(100);
}
Ten komentarz został usunięty przez autora.
OdpowiedzUsuń