Working serial, text scrolling
This commit is contained in:
commit
7fbc7230dc
3 changed files with 210 additions and 0 deletions
76
layout.ino
Normal file
76
layout.ino
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
Define one function to control all of the layout.
|
||||
It works per line with only one variable (tick).
|
||||
This one gives a way of scrolling through text.
|
||||
|
||||
*/
|
||||
|
||||
void layout(unsigned int tick) {
|
||||
display.clearDisplay();
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
display.setTextWrap(false);
|
||||
|
||||
updateLine1(tick);
|
||||
updateLine2(tick);
|
||||
updateLine3(tick);
|
||||
updateLine4(tick);
|
||||
|
||||
display.display();
|
||||
}
|
||||
void updateLine1(unsigned int tick) {
|
||||
//reset line
|
||||
display.drawRect(0, 0, display.width(), 8, BLACK);
|
||||
display.setCursor(0, 0);
|
||||
// First line (20)
|
||||
if (volume < 100 ) display.print(' ');
|
||||
display.print(volume);
|
||||
display.print(F("% "));
|
||||
display.print(F("|mm:ss/mm:ss|"));
|
||||
display.print(F(" "));
|
||||
if (repeat) display.print('r');
|
||||
else display.print('-');
|
||||
if (shuffle) display.print('z');
|
||||
else display.print('-');
|
||||
|
||||
}
|
||||
void updateLine2(unsigned int tick) {
|
||||
//reset line
|
||||
display.drawRect(0, 8, display.width(), 16, BLACK);
|
||||
display.setCursor(0, 8);
|
||||
display.print(textscroll(title,tick));
|
||||
display.startscrollleft(0x06, 0x0F);
|
||||
|
||||
}
|
||||
void updateLine3(unsigned int tick) {
|
||||
//reset line
|
||||
display.drawRect(0, 16, display.width(), 24, BLACK);
|
||||
display.setCursor(0, 16);
|
||||
display.print(textscroll(artist, tick));
|
||||
|
||||
}
|
||||
void updateLine4(unsigned int tick) {
|
||||
//reset line
|
||||
display.drawRect(0, 24, display.width(), 32, BLACK);
|
||||
display.setCursor(0, 24);
|
||||
display.print(textscroll(album, tick));
|
||||
}
|
||||
|
||||
String textscroll(String text, unsigned int tick) {
|
||||
int chars = 21;
|
||||
int len = text.length();
|
||||
String newstring = "";
|
||||
|
||||
if ( len < chars) return text;
|
||||
|
||||
text = text + " - ";
|
||||
for ( int i = 0; i < chars; i++ )
|
||||
newstring += text.charAt((tick + i) % (len+3));
|
||||
|
||||
return newstring;
|
||||
}
|
||||
|
||||
int calcMaxTicks() {
|
||||
maxticks = title.length() * artist.length() * album.length();
|
||||
return maxticks;
|
||||
}
|
80
mpcArduino.ino
Normal file
80
mpcArduino.ino
Normal file
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
Project to interface a screen connected to an arduino with data from a vash script.
|
||||
Used as start up for a HTPC.
|
||||
*/
|
||||
// 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 = false;
|
||||
boolean shuffle = false;
|
||||
int volume = 100;
|
||||
String title = "Yesterdays";
|
||||
String artist = "Guns 'n Roses";
|
||||
String album = "Appetite for Destruction";
|
||||
|
||||
unsigned int tick = 0;
|
||||
unsigned int maxticks = 0;
|
||||
|
||||
void setup() {
|
||||
// initialise serial
|
||||
Serial.begin(9600);
|
||||
// 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(500);
|
||||
layout(tick);
|
||||
calcMaxTicks();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// print the string when a newline arrives:
|
||||
if (stringComplete) {
|
||||
setFromSerial( inputString );
|
||||
}
|
||||
layout(tick++);
|
||||
if ( tick > maxticks ) tick = 0;
|
||||
delay(500);
|
||||
}
|
54
serial.ino
Normal file
54
serial.ino
Normal file
|
@ -0,0 +1,54 @@
|
|||
|
||||
/*
|
||||
SerialEvent occurs whenever a new data comes in the
|
||||
hardware serial RX. This routine is run between each
|
||||
time loop() runs, so using delay inside loop can delay
|
||||
response. Multiple bytes of data may be available.
|
||||
*/
|
||||
void serialEvent() {
|
||||
while (Serial.available()) {
|
||||
// get the new byte:
|
||||
char inChar = (char)Serial.read();
|
||||
// add it to the inputString:
|
||||
inputString += inChar;
|
||||
// if the incoming character is a newline, set a flag
|
||||
// so the main loop can do something about it:
|
||||
if (inChar == '\n') {
|
||||
stringComplete = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setFromSerial (String inputString) {
|
||||
//remove newline
|
||||
inputString = inputString.substring(0, inputString.length() -1);
|
||||
switch ( inputString.charAt(0) ) {
|
||||
case 'V':
|
||||
volume = inputString.substring(1).toInt();
|
||||
break;
|
||||
case 'T':
|
||||
title = inputString.substring(1);
|
||||
break;
|
||||
case 'A':
|
||||
artist = inputString.substring(1);
|
||||
break;
|
||||
case 'a':
|
||||
album = inputString.substring(1);
|
||||
break;
|
||||
case 'r':
|
||||
repeat = inputString.substring(1) != 0;
|
||||
break;
|
||||
case 'z':
|
||||
shuffle = inputString.substring(1) != 0;
|
||||
break;
|
||||
default:
|
||||
Serial.println(F("!Invalid line:"));
|
||||
Serial.print(F("!"));
|
||||
Serial.println(inputString);
|
||||
break;
|
||||
}
|
||||
calcMaxTicks();
|
||||
// clear the string:
|
||||
inputString = "";
|
||||
stringComplete = false;
|
||||
}
|
Loading…
Reference in a new issue