135 lines
3.0 KiB
C++
135 lines
3.0 KiB
C++
/*
|
|
Project to interface a screen connected to an arduino with data from a vash script.
|
|
Used as start up for a HTPC.
|
|
*/
|
|
|
|
#define BAUD 9600
|
|
#define MAIN_DELAY 500
|
|
#define DHT_DELAY 10000
|
|
|
|
// STRING Commands
|
|
#define KEY_RESET 'R'
|
|
#define KEY_READ 'E'
|
|
#define KEY_ECHO '!'
|
|
#define KEY_SET 'S'
|
|
//MPD
|
|
#define KEY_VOLUME 'V'
|
|
#define KEY_TITLE 'T'
|
|
#define KEY_ARTIST 'A'
|
|
#define KEY_ALBUM 'a'
|
|
#define KEY_REPEAT 'r'
|
|
#define KEY_SHUFFLE 'z'
|
|
#define KEY_RANDOM 'x'
|
|
#define KEY_CONSUME 'c'
|
|
#define KEY_UPDATE 'u'
|
|
#define KEY_SINGLE 's'
|
|
#define KEY_PLAYING 'P'
|
|
//Sensors
|
|
#define KEY_DHT_HUMIDITY 'h'
|
|
#define KEY_DHT_TEMPERATURE 't'
|
|
|
|
|
|
// DHT
|
|
#include <DHT.h>
|
|
#define DHTPIN 7 // what pin we're connected to
|
|
#define DHTTYPE DHT22 // DHT 22 (AM2302)
|
|
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
|
|
|
|
// OLED thingies
|
|
#include <SPI.h>
|
|
#include <Wire.h>
|
|
#include <Adafruit_GFX.h>
|
|
#include <Adafruit_SSD1306.h>
|
|
|
|
//Functionality
|
|
#define OLED_RESET 4
|
|
Adafruit_SSD1306 display(OLED_RESET);
|
|
|
|
#define NUMFLAKES 10
|
|
#define XPOS 0
|
|
#define YPOS 1
|
|
#define DELTAY 2
|
|
|
|
|
|
#define LOGO16_GLCD_HEIGHT 16
|
|
#define LOGO16_GLCD_WIDTH 16
|
|
static const unsigned char PROGMEM logo16_glcd_bmp[] =
|
|
{ B00000000, B11000000,
|
|
B00000001, B11000000,
|
|
B00000001, B11000000,
|
|
B00000011, B11100000,
|
|
B11110011, B11100000,
|
|
B11111110, B11111000,
|
|
B01111110, B11111111,
|
|
B00110011, B10011111,
|
|
B00011111, B11111100,
|
|
B00001101, B01110000,
|
|
B00011011, B10100000,
|
|
B00111111, B11100000,
|
|
B00111111, B11110000,
|
|
B01111100, B11110000,
|
|
B01110000, B01110000,
|
|
B00000000, B00110000 };
|
|
|
|
#if (SSD1306_LCDHEIGHT != 32)
|
|
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
|
|
#endif
|
|
|
|
|
|
// Vars
|
|
String inputString = ""; // a string to hold incoming data
|
|
boolean stringComplete = false; // whether the string is complete
|
|
|
|
boolean repeat_bool = false;
|
|
boolean shuffle_bool = false;
|
|
boolean consume_bool = false;
|
|
boolean random_bool = false;
|
|
boolean updating_bool = false;
|
|
boolean single_bool = false;
|
|
boolean playing = false;
|
|
|
|
int volume = 100;
|
|
String title = " << << Title >> >> ";
|
|
String artist = " << << Artist >> >> ";
|
|
String album = " << << Album >> >> ";
|
|
|
|
float humidity = 0;
|
|
float temperature = 0;
|
|
|
|
unsigned int tick = 0;
|
|
unsigned int maxticks = 0;
|
|
|
|
void setup() {
|
|
// initialise serial
|
|
Serial.begin(BAUD);
|
|
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
|
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
|
|
// init done
|
|
display.clearDisplay();
|
|
display.display();
|
|
delay(MAIN_DELAY);
|
|
|
|
initial_layout();
|
|
while(!Serial);
|
|
establishContact();
|
|
layout(tick);
|
|
calcMaxTicks();
|
|
|
|
|
|
}
|
|
|
|
void loop() {
|
|
// print the string when a newline arrives:
|
|
if (stringComplete) {
|
|
setFromSerial( inputString );
|
|
|
|
// clear the string:
|
|
inputString = "";
|
|
stringComplete = false;
|
|
}
|
|
layout(tick++);
|
|
update_sensor_readings(tick);
|
|
if ( tick > maxticks ) tick = 0;
|
|
delay(MAIN_DELAY);
|
|
}
|