#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <RotaryEncoder.h> //https://github.com/mathertel/RotaryEncoder
#define PIN_IN1 4
#define PIN_IN2 3
RotaryEncoder encoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::TWO03);
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
// Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
#define color1 0xC638
#define color2 0xC638
int value = 980;
int minimal = 880;
int maximal = 1080;
int strength = 0;
String sta[6] = {"96.6", "101.0", "89.4", "106,5", "98.2", "92.4"};
bool muted = 0;
int deb = 0;
float freq = 89.25;
void setup() {
tft.begin();
tft.fillScreen(ILI9341_BLACK);
yield();
tft.setRotation(1);
drawSprite();
}
void loop()
{
readEncoder();
}
void readEncoder()
{
static int pos = 0;
encoder.tick();
if (digitalRead(2) == 0)
{
if (deb == 0)
{
deb = 1;
muted = !muted;
//radio.setMuted(muted);
drawSprite();
delay(200);
}
} else deb = 0;
int newPos = encoder.getPosition();
if (pos != newPos)
{
if (newPos > pos)
{
value = value - 1;
}
if (newPos < pos)
{
value = value + 1;
}
pos = newPos;
drawSprite();
}
}
void drawSprite()
{
freq = value / 10.00;
if (muted == false)
{
//radio.setFrequency(freq);
}
//strength = radio.getSignalLevel();
strength = 9;
tft.setTextColor(ILI9341_CYAN, ILI9341_BLACK);
tft.setTextSize(4);
tft.setCursor(10, 50);
tft.print(freq);
tft.setTextSize(2);
tft.setCursor(260, 60);
tft.print("MHz");
tft.setCursor(10, 6);
tft.setTextColor(ILI9341_ORANGE, ILI9341_BLACK);
tft.print("TEA5767 - FM Radio");
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.drawRoundRect(186, 142, 128, 32, 8, ILI9341_WHITE);
tft.drawRect(290, 6, 20, 9, ILI9341_WHITE);
tft.fillRect(291, 7, 12, 7, 0x34CD);
tft.fillRect(310, 8, 2, 5, ILI9341_WHITE);
tft.setTextColor(0xBEDF, ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE, ILI9341_BLACK);
tft.setCursor(10, 128);
tft.print("SEMNAL:");
tft.setCursor(10, 164);
tft.print("MUTE");
tft.fillRoundRect(80, 152, 40, 40, 6, 0xCC40);
if (muted == 1)
{
tft.fillCircle(100, 170, 12, ILI9341_WHITE);
}
//nivel semnal
for (int i = 0; i < strength; i++)
{
tft.fillRect(120 + (i * 4), 130 - (i * 2), 4, 8 + (i * 2), 0x3526);
}
tft.fillTriangle(152, 168, 160, 188, 168, 168, ILI9341_RED);
int temp = value - 40;
for (int i = 0; i < 40; i++)
{
if ((temp % 10) == 0)
{
tft.drawLine(i * 8, 256, i * 8, 220, color1);
tft.drawLine((i * 8) + 2, 256, (i * 8) + 2, 220, color1);
tft.setCursor(i * 8, 196);
tft.setTextSize(1);
tft.print (temp / 10.0);
}
else if ((temp % 5) == 0 && (temp % 10) != 0)
{ tft.drawLine(i * 8, 256, i * 8, 230, color1);
tft.drawLine((i * 8) + 2, 256, (i * 8) + 2, 230, color1);
}
else
{
tft.drawLine(i * 8, 256, i * 8, 236, color1);
}
temp = temp + 2;
}
tft.setCursor(200, 150);
tft.print("Stereo: ");
//tft.print("Stereo: " + String(radio.isStereo()));
tft.drawLine(160, 168, 160, 256, ILI9341_RED);
}