#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RotaryEncoder.h>
#define OLED_RESET 4
#define PIN_IN1 2
#define PIN_IN2 3
float freq = 101.5;
int vol = 10;
int rssi = 54;
char buffer[6];
char buffer2[6];
char buffer3[6];
Adafruit_SSD1306 oled(128, 64);
RotaryEncoder encoder(PIN_IN1, PIN_IN2, RotaryEncoder::LatchMode::TWO03);
void setup()
{
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(200);
oled.clearDisplay();
updateLCD();
}
void loop()
{
readEncoder();
}
void updateLCD()
{
oled.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
if (freq > 100.0) {
oled.setCursor(0, 10);
oled.clearDisplay();
}
else {
oled.setCursor(18, 10);
oled.clearDisplay();
}
oled.drawRect(0, 1, 127, 2, SSD1306_WHITE);
dtostrf(freq, 2, 1, buffer);
oled.setTextSize(3);
oled.print(buffer);
oled.drawRect(0, 38, 127, 2, SSD1306_WHITE);
oled.setCursor(97, 10);
oled.setTextSize(2);
oled.print("FM");
oled.setCursor(92, 25);
oled.setTextSize(1);
oled.print("STEREO");
sprintf(buffer2, "Level:%3d", rssi);
oled.setCursor(4, 48);
oled.print(buffer2);
sprintf(buffer3, "Vol:%2d", vol);
oled.setCursor(80, 48);
oled.print(buffer3);
oled.write(37);
oled.fillRect(0, 45, 127, 14, SSD1306_INVERSE);
oled.display();
}
void readEncoder() {
static int pos = 0;
encoder.tick();
int newPos = encoder.getPosition();
if (pos != newPos) {
if (newPos > pos)
freq = freq - 0.1;
if (newPos < pos)
freq = freq + 0.1;
pos = newPos;
if (freq > 108.0)freq = 108.0;
if (freq < 87.0)freq = 87.0;
updateLCD();
}
}
nano:12
nano:11
nano:10
nano:9
nano:8
nano:7
nano:6
nano:5
nano:4
nano:3
nano:2
nano:GND.2
nano:RESET.2
nano:0
nano:1
nano:13
nano:3.3V
nano:AREF
nano:A0
nano:A1
nano:A2
nano:A3
nano:A4
nano:A5
nano:A6
nano:A7
nano:5V
nano:RESET
nano:GND.1
nano:VIN
nano:12.2
nano:5V.2
nano:13.2
nano:11.2
nano:RESET.3
nano:GND.3
Loading
ssd1306
ssd1306
encoder1:CLK
encoder1:DT
encoder1:SW
encoder1:VCC
encoder1:GND