#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "SoftwareSerial.h"
// Rock band Jukebox
// by Roni Bandini @RoniBandini
// Buenos Aires, Argentina
// September 2018
LiquidCrystal_I2C lcd(0x3F,16,2);
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00
# define ACTIVATED LOW
int button1 = 2;
int button2 = 3;
int button3 = 4;
void setup() {
pinMode(button2, INPUT);
digitalWrite(button2,HIGH);
pinMode(button1, INPUT);
digitalWrite(button1,HIGH);
pinMode(button3, INPUT);
digitalWrite(button3,HIGH);
mySerial.begin (9600);
Serial.begin(115200);
Serial.println();
Serial.println(F("Jukebox started"));
lcd.init();
lcd.backlight();
lcd.print("RockBand Jukebox");
lcd.setCursor(0, 1);
lcd.print("by RoniBandini");
playFirst();
//isPlaying = true;
delay (3000);
lcd.print("RockBand Jukebox");
lcd.setCursor(0, 1);
lcd.print("Select song ");
}
void loop () {
if (digitalRead(button1) == ACTIVATED)
{
Serial.println(F("Play 1..."));
lcd.print("RockBand Jukebox");
lcd.setCursor(0, 1);
lcd.print("Song 1 ");
//playNext();
execute_CMD(0x0F,0x01,0x01);
}
if (digitalRead(button2) == ACTIVATED)
{
Serial.println(F("Play 2..."));
lcd.print("RockBand Jukebox");
lcd.setCursor(0, 1);
lcd.print("Song 2 ");
//playNext();
execute_CMD(0x0F,0x01,0x002);
}
if (digitalRead(button3) == ACTIVATED)
{
Serial.println(F("Play 3..."));
lcd.print("RockBand Jukebox");
lcd.setCursor(0, 1);
lcd.print("Song 3 ");
//playNext();
execute_CMD(0x0F,0x01,0x03);
}
}
void playFirst()
{
execute_CMD(0x3F, 0, 0);
delay(500);
setVolume(25);
delay(500);
//execute_CMD(0x11,0,1);
//delay(500);
}
void pause()
{
execute_CMD(0x0E,0,0);
delay(500);
}
void play()
{
execute_CMD(0x0D,0,1);
delay(500);
}
void playNext()
{
execute_CMD(0x01,0,1);
delay(500);
}
void playPrevious()
{
execute_CMD(0x02,0,1);
delay(500);
}
void setVolume(int volume)
{
execute_CMD(0x06, 0, volume);
delay(2000);
}
void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
mySerial.write( Command_line[k]);
}
}