Created
June 25, 2017 15:55
-
-
Save mstaack/5d07819b28894a4a3a018e81727ec7dd to your computer and use it in GitHub Desktop.
webradio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//diy webradio with atmega328 & carambola2 board by m.staack | |
#include <Wire.h> | |
#include <LiquidCrystal_I2C.h> | |
#include <SoftwareSerial.h> | |
#include <Encoder.h> | |
#include <EEPROM.h> | |
#include <SPI.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_SSD1306.h> | |
#define OLED_RESET 4 | |
Adafruit_SSD1306 display(OLED_RESET); | |
const int ledPin = 11; | |
SoftwareSerial carambola(10, 9); //RX, TX | |
Encoder rotary(7, 8); | |
const int stationsCount = 7; | |
typedef struct { | |
char* remote_name; | |
char* remote_host; | |
} Station; | |
Station stations[stationsCount] = { | |
{ "NONE", "NONE" }, | |
{ "Deep Mix Moscow", "94.176.104.15:8128" }, | |
{ "1213 rap", "184.154.90.186:8077" }, | |
{ "Amsterdam Hiphop", "77.168.22.74:8008/stream" }, | |
{ "Deep Jams Rock", "s8.voscast.com:9748" }, | |
{ "SmoothChoice Jazz ", "193.226.19.131:7015" }, | |
{ "The Funkstation! ", "84.24.194.99:8000" } | |
}; | |
int stationPosition = 0; | |
int rotaryPosition = 0; | |
int changed = 1; | |
void setup() { | |
// initialize the digital pin as an output. | |
pinMode(ledPin, OUTPUT); | |
carambola.begin(115200); | |
Serial.begin(9600); // USB is always 12 Mbit/sec | |
// init display | |
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32) | |
display.clearDisplay(); | |
display.setTextSize(1); | |
display.setTextColor(WHITE); | |
display.setCursor(0, 0); | |
display.println("Booting..."); | |
display.display(); | |
stationPosition = EEPROM.read(00); | |
Serial.print(stationPosition); | |
delay(60000); | |
carambola.println(); | |
carambola.flush(); | |
} | |
void loop() { | |
int newPosition = rotary.read() / 2; | |
if (newPosition > rotaryPosition && stationPosition < stationsCount - 1) | |
{ | |
stationPosition++; | |
changed = 1; | |
} | |
if (newPosition < rotaryPosition && stationPosition > 0) | |
{ | |
stationPosition--; | |
changed = 1; | |
} | |
rotaryPosition = newPosition; | |
if (changed == 1) { | |
update(); | |
changed = 0; | |
} | |
} | |
void update(){ | |
refreshScreen(); | |
stopAll(); | |
delay(80); | |
openStream(); | |
persist(); | |
} | |
void persist() { | |
EEPROM.write(00, stationPosition); | |
Serial.print("save:"); | |
Serial.print(stationPosition + 1); | |
} | |
void openStream() { | |
carambola.println(); | |
carambola.print("wget -q -O - http://"); | |
carambola.print(stations[stationPosition].remote_host); | |
carambola.print(" | madplay - > /dev/null 2>&1 &"); | |
carambola.println(); | |
} | |
void stopAll() { | |
carambola.println("kill `pidof madplay`"); | |
} | |
void refreshScreen() { | |
display.clearDisplay(); | |
display.setCursor(0, 0); | |
display.println("No Stress Sound v2"); | |
display.drawLine(0, 8, 128, 8, WHITE); | |
display.setCursor(0, 22); | |
display.print(stations[stationPosition].remote_name); | |
display.setCursor(110, 22); | |
display.print(stationPosition + 1); | |
display.print("/"); | |
display.print(stationsCount); | |
display.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment