/* 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; }