#include <SPI.h>
#include <RA8875.h>
#include <SD.h>
#include <Encoder.h>
#include <Bounce2.h>
#include <Wire.h>
#include <SerialFlash.h>
#include <Audio.h>
Encoder Oben(0, 1);
Encoder Unten(5, 4);
byte positionOben = 255;
byte positionUnten = 15;
byte MenuObenKnopf;
byte MenuObenZaehler = 0;
byte MenuObenZaehleralt;
byte MenuObenEbene = 0;
byte MenuObenEbenealt;
byte MenuUntenKnopf;
byte MenuUntenZaehler = 0;
byte MenuUntenZaehleralt;
byte MenuUntenEbene = 0;
byte MenuUntenEbenealt;
byte aktiverBildSchirm;
#define KnopfObenPIN 2
#define KnopfUntenPIN 21
Bounce debouncer1 = Bounce();
Bounce debouncer2 = Bounce();
#define RA8875_CS 9
#define RA8875_RESET 20
#define RA8875_MOSI 7
#define RA8875_SCLK 14
#define RA8875_MISO 8
#define SD_DEC 29 //in
RA8875 tft = RA8875(RA8875_CS,RA8875_RESET,RA8875_MOSI,RA8875_SCLK,RA8875_MISO);//Teensy using alternative SPI pin + alt miso
AudioInputI2S i2s1; //xy=200,69
AudioOutputI2S i2s2; //xy=365,94
AudioConnection patchCord1(i2s1, 0, i2s2, 0);
AudioConnection patchCord2(i2s1, 1, i2s2, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=302,184
const int myInput = AUDIO_INPUT_LINEIN;
void setup()
{
Serial.begin(115200);
Serial.println("RA8875 start");
tft.begin(RA8875_800x480);
tft.println("starte Radio.... na, was sagst du nun?");
tft.brightness(25);
tft.setRotation(2);
pinMode(KnopfObenPIN,INPUT_PULLUP);
debouncer1.attach(KnopfObenPIN);
debouncer1.interval(20);
pinMode(KnopfUntenPIN,INPUT_PULLUP);
debouncer2.attach(KnopfUntenPIN);
debouncer2.interval(20);
AudioMemory(12);
/*sgtl5000_1.enable();
sgtl5000_1.inputSelect(myInput);
sgtl5000_1.volume(0.7);*/
}
elapsedMillis volmsec=0;
void loop()
{
DrehEncoder();
MenuWahl();
//Kalender();
//SDCardPlayer();
//Sonnenberechnung();
//Uhr();
}
void StartBildSchirm()
{
tft.clearScreen();
tft.setCursor(0, 60);
tft.setTextColor(RA8875_BLUE);
tft.setFontScale(2);
tft.print("StartBildschirm ");
aktiverBildSchirm = 0;
}
void MenuBildSchirm()
{
tft.clearScreen();
tft.drawRoundRect( 5, 60, 250, 40, 5, RA8875_DARK_ORANGE);
tft.fillRoundRect( 6, 61, 248, 38, 4, RA8875_LIGHT_GREY);
tft.drawRoundRect( 5, 110, 250, 40, 5, RA8875_DARK_ORANGE);
tft.fillRoundRect( 6, 111, 248, 38, 4, RA8875_LIGHT_GREY);
tft.drawRoundRect( 5, 160, 250, 40, 5, RA8875_DARK_ORANGE);
tft.fillRoundRect( 6, 161, 248, 38, 4, RA8875_LIGHT_GREY);
tft.drawRoundRect( 5, 210, 250, 40, 5, RA8875_DARK_ORANGE);
tft.fillRoundRect( 6, 211, 248, 38, 4, RA8875_LIGHT_GREY);
tft.drawRoundRect( 5, 260, 250, 40, 5, RA8875_DARK_ORANGE);
tft.fillRoundRect( 6, 261, 248, 38, 4, RA8875_LIGHT_GREY);
tft.drawRoundRect( 5, 310, 250, 40, 5, RA8875_DARK_ORANGE);
tft.fillRoundRect( 6, 311, 248, 38, 4, RA8875_LIGHT_GREY);
tft.setTextColor(RA8875_BLUE);
tft.setFontScale(1);
tft.setCursor(20, 60);
tft.print("zurueck ");
tft.setCursor(20, 110);
tft.print("Radio ");
tft.setCursor(20, 160);
tft.print("eigene Musik ");
tft.setCursor(20, 210);
tft.print("einschlafen ");
tft.setCursor(20, 260);
tft.print("wecken ");
tft.setCursor(20, 310);
tft.print("Uhr ");
aktiverBildSchirm = 1;
}
void RadioBildSchirm()
{
tft.clearScreen();
tft.setCursor(0, 60);
tft.setTextColor(RA8875_BLUE);
tft.setFontScale(1);
tft.print("Radio ");
aktiverBildSchirm = 2;
}
void SDBildSchirm()
{
tft.clearScreen();
tft.setCursor(0, 60);
tft.setTextColor(RA8875_BLUE);
tft.setFontScale(1);
tft.print("eigene Musik ");
aktiverBildSchirm = 3;
}
void EinschlafTimerBildSchirm()
{
tft.clearScreen();
tft.setCursor(0, 60);
tft.setTextColor(RA8875_BLUE);
tft.setFontScale(1);
tft.print("Schlafen ");
aktiverBildSchirm = 4;
}
void WeckerBildSchirm()
{
tft.clearScreen();
tft.setCursor(0, 60);
tft.setTextColor(RA8875_BLUE);
tft.setFontScale(1);
tft.print("Wecker ");
aktiverBildSchirm = 5;
}
void UhrBildSchirm()
{
tft.clearScreen();
tft.setCursor(0, 60);
tft.setTextColor(RA8875_BLUE);
tft.setFontScale(1);
tft.print("Uhr ");
aktiverBildSchirm = 6;
}
void MenuWahl()
{
if ( MenuUntenEbene == 0 && debouncer2.rose() )
{ MenuUntenEbene = 1; Unten.write(0); MenuBildSchirm(); }
if ( MenuUntenEbene == 1 )
{
if ( MenuUntenZaehler > 6 ) { Unten.write(0); }
if ( MenuUntenZaehler == 0 )
{ if ( MenuUntenZaehler != MenuUntenZaehleralt )
{ tft.drawRoundRect( 5, 60, 250, 40, 5, RA8875_YELLOW);
tft.drawRoundRect( 5, 110, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 160, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 210, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 260, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 310, 250, 40, 5, RA8875_DARK_ORANGE);
MenuUntenZaehleralt = MenuUntenZaehler; }
if ( debouncer2.fell() ) { MenuUntenEbene = 0; Unten.write(0); tft.fillWindow(); StartBildSchirm(); } }
if ( MenuUntenZaehler == 1 )
{ if ( MenuUntenZaehler != MenuUntenZaehleralt )
{ tft.drawRoundRect( 5, 60, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 110, 250, 40, 5, RA8875_YELLOW);
tft.drawRoundRect( 5, 160, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 210, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 260, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 310, 250, 40, 5, RA8875_DARK_ORANGE);
MenuUntenZaehleralt = MenuUntenZaehler; }
if ( debouncer2.rose() ) { MenuUntenEbene = 2; Unten.write(0); tft.fillWindow(); RadioBildSchirm(); RadioAktiv();} }
if ( MenuUntenZaehler == 2 )
{ if ( MenuUntenZaehler != MenuUntenZaehleralt )
{ tft.drawRoundRect( 5, 60, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 110, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 160, 250, 40, 5, RA8875_YELLOW);
tft.drawRoundRect( 5, 210, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 260, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 310, 250, 40, 5, RA8875_DARK_ORANGE);
MenuUntenZaehleralt = MenuUntenZaehler; }
if ( debouncer2.rose() ) { MenuUntenEbene = 3; Unten.write(0); tft.fillWindow(); SDBildSchirm(); } }
if ( MenuUntenZaehler == 3 )
{ if ( MenuUntenZaehler != MenuUntenZaehleralt )
{ tft.drawRoundRect( 5, 60, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 110, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 160, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 210, 250, 40, 5, RA8875_YELLOW);
tft.drawRoundRect( 5, 260, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 310, 250, 40, 5, RA8875_DARK_ORANGE);
MenuUntenZaehleralt = MenuUntenZaehler; }
if ( debouncer2.rose() ) { MenuUntenEbene = 4; Unten.write(0); tft.fillWindow(); EinschlafTimerBildSchirm(); } }
if ( MenuUntenZaehler == 4 )
{ if ( MenuUntenZaehler != MenuUntenZaehleralt )
{ tft.drawRoundRect( 5, 60, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 110, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 160, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 210, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 260, 250, 40, 5, RA8875_YELLOW);
tft.drawRoundRect( 5, 310, 250, 40, 5, RA8875_DARK_ORANGE);
MenuUntenZaehleralt = MenuUntenZaehler; }
if ( debouncer2.rose() ) { MenuUntenEbene = 5; Unten.write(0); tft.fillWindow(); WeckerBildSchirm(); } }
if ( MenuUntenZaehler == 5 )
{ if ( MenuUntenZaehler != MenuUntenZaehleralt )
{ tft.drawRoundRect( 5, 60, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 110, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 160, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 210, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 260, 250, 40, 5, RA8875_DARK_ORANGE);
tft.drawRoundRect( 5, 310, 250, 40, 5, RA8875_YELLOW);
MenuUntenZaehleralt = MenuUntenZaehler; }
if ( debouncer2.rose() ) { MenuUntenEbene = 6; Unten.write(0); tft.fillWindow(); UhrBildSchirm(); } }
}
if ( MenuUntenEbene == 2 && MenuUntenZaehler == 0 && debouncer2.rose() )
{ MenuUntenEbene = 1; MenuBildSchirm();}
if ( MenuUntenEbene == 3 && MenuUntenZaehler == 0 && debouncer2.rose() )
{ MenuUntenEbene = 1; MenuBildSchirm();}
if ( MenuUntenEbene == 4 && MenuUntenZaehler == 0 && debouncer2.rose() )
{ MenuUntenEbene = 1; MenuBildSchirm();}
if ( MenuUntenEbene == 5 && MenuUntenZaehler == 0 && debouncer2.rose() )
{ MenuUntenEbene = 1; MenuBildSchirm();}
if ( MenuUntenEbene == 6 && MenuUntenZaehler == 0 && debouncer2.rose() )
{ MenuUntenEbene = 1; MenuBildSchirm();}
//else { StartBildSchirm(); }
if ( debouncer1.fell() || debouncer1.rose() )
{ Serial.print("Menu Ebene oben ");
Serial.println(MenuObenEbene);}
if ( debouncer2.fell() || debouncer2.rose() )
{ Serial.print("Menu Ebene unten ");
Serial.println(MenuUntenEbene);}
}
void DrehEncoder()
{
MenuObenZaehler = Oben.read()/4;
MenuUntenZaehler = Unten.read()/4;
debouncer1.update();
debouncer2.update();
if (MenuObenZaehler != positionOben)
{
positionOben = MenuObenZaehler;
Serial.print("Menu Zaehler oben ");
Serial.println(MenuObenZaehler);
}
if (MenuUntenZaehler != positionUnten)
{
positionUnten = MenuUntenZaehler;
Serial.print("Menu Zaehler unten ");
Serial.println(MenuUntenZaehler);
}
}
void RadioAktiv()
{
}