I have a sprite media player and thought i would try and control it with an arduino, i have a little understanding of code, but very much a newbie, i would appreciate if anyone could gve me a hint to where i am getting confused with what i have done so far or advise the method i should be researching to achieve my aim, the first code shown i got working , but then i decided to see if i could use another button to select which video to play with an end goal of trying to create a kind of media player jukebox idea . I have looked for code on the web showing me how i could change a variable with a button but it all to relate relate to just changing from 0 to 1 where i wanted to use the file name of the video, i then thought i could just simply set a preset value in the variable at start up check for the button being pressed and reset the variable but that seems to loop round and resets itself. so that didnt work.
Thanks in advance
const int button = 3; //Define our button pin
int buttonStatus = 1; //Sets the default button status
int playing = 0; //Defines whether or not the file is playing and sets it to NO.
void setup() {
Serial.begin(9600); //Start the serial connection that will communicate with the Sprite
pinMode(3, INPUT_PULLUP);
}
void loop() {
buttonStatus = digitalRead(button); //Reads whether or not our button or switch is flipped
if (buttonStatus == 0 && playing == 0){
playing = 1; //Set our playing variable to yes so when dont send two signals
Serial.write(0x01); //If the button or switch is flipped, we send signal to the sprite to play file 001.xxx
}
if (Serial.read() == 0xEE){
playing = 0; // When the Sprite finishes a file it sends a finished signal so we use that to tell the arduino it is no longer playing a file.
buttonStatus = 1;
delay(10000); //unsigned long
}
}
second code is what i tried to make it check a button and if pressed change the video status variable so it would play the second video i added instead of the first.
/* Arduino Code for Sprite
*
* 2021
*/
const int button = 3; //Define our button pin
const int videos = 4; // buttons pin video choice
int buttonStatus = 1; //Sets the default button status
int playing = 0; //Defines whether or not the file is playing and sets it to NO.
int videoStatus = 1; // defines whether to play video 1 or 4, 1 - play video 1, 0 - play video 4
//1 is default setting after any video has played and eof command recieved.
void setup() {
Serial.begin(9600); //Start the serial connection that will communicate with the Sprite
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
}
void loop() {
buttonStatus = digitalRead(button); //Reads whether or not our button or switch is flipped
videoStatus = digitalRead(videos); // reads video select button
if (buttonStatus == 0 && videoStatus == 1 && playing == 0){
playing = 1; //Set our playing variable to yes so when dont send two signals
Serial.write(0x01); //If the input voltage is 0, we send signal to the sprite to play file 001.xxx
}
else {
(buttonStatus == 0 && videoStatus == 0 && playing == 0);
playing = 1; //Set our playing variable to yes so when dont send two signals
Serial.write(0x04); //If the input voltage is 0, we send signal to the sprite to play file 004.xxx,
}
if (Serial.read() == 0xEE){
playing = 0; // When the Sprite finishes a file it sends a finished signal so we use that to tell the arduino it is no longer playing a file.
buttonStatus = 1; // set control voltage variable back to 1
delay(10000); //delay to ensure control input voltage has reverted to high
}
}
if (buttonStatus == 0 && playing == 0)
{
playing = 1; //Set our playing variable to yes so when dont send two signals
if (videoStatus == 1)
{
Serial.write(0x01); //If the input voltage is 0, we send signal to the sprite to play file 001.xxx
}
else if (videoStatus == 0)
{
Serial.write(0x04); //If the input voltage is 0, we send signal to the sprite to play file 004.xxx,
}
}
Hi guix,
thank you , so close yet so much to learn, so it seems i just overcomplicated it by checking the third item in the one line when i could have tested that seprately, i have just started going through the tutorials on this forum, this seeemingly silly project is sparking a new interest for me .
So , i may have got the syntax wrong but it still didnt work , so as i had printed the tutorial by robin2 about getting a program to do many things , i decided to rethink and rewrite the entire project of using the arduino uno to control my sprite media player following his method (for fun as the sprite has a remote control!!)
I wrote out what i wanted it to do , then set about putting the tasks in seperate functions and testing each step or function to see that it did what i intended and then added the second function and it all works, i will expand on this as i experiment with further control.
I know this to a seasoned programmer will seem over complicated for such a simple task but as i really had no idea was quite pleased with myself that i had made it work . If anyone was interested in writing it as one complete block to see why i couldnt make it work that way would be great , but mine works now so first arduino program under my belt.
my code is below , any suggestions constructive comments appreciated.
/* Arduino Code for Sprite
* M Smith
* 2021
*/
const int button = 3; //Define our button pin (crestron voltage in)
const int videos = 4; // buttons pin video if second video is one to play (safetyvideeo)
int buttonStatus = 1; //Sets the default button status (indicates off state of crestron HIGH pin)
int videoStatus = 1; // defines whether to play video 1 or 4, 1 - play video 1, 0 - play video 4
//1 is default setting after any video has played and eof command recieved.
int playing = 0; //Defines whether or not the file is playing and sets it to NO.
void setup() {
Serial.begin(9600); //Start the serial connection that will communicate with the Sprite
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
}
void loop() {
buttonStatus = digitalRead(button); //Reads whether or not our button or switch is flipped
videoStatus = digitalRead(videos); // reads video select button
mainMovie();
safetyVideo();
if (Serial.read() == 0xEE){
playing = 0; // When the Sprite finishes a file it sends a finished signal so we use that to tell the arduino it is no longer playing a file.
}
}
void mainMovie(){
if (buttonStatus == 0 && playing == 0){
playing = 1; //Set our playing variable to yes so when dont send two signals
Serial.write(0x01); //If the button or switch is flipped, we send signal to the sprite to play file 001.xxx
}
}
void safetyVideo(){
if (videoStatus == 0 && playing == 0){
playing = 1; //Set our playing variable to yes so when dont send two signals
Serial.write(0x04); //If the input voltage is 0, we send signal to the sprite to play file 004.xxx
}
}
So i have now progressed further and can get the mainvideo to play, respond correctly to its input voltage , i then tried to add the option to play the second video if a pushbutton was pressed and providing the criteria for playing a video was met. ie the other video not playing and the external control system is in ready (standby ) mode.
no matter what i try i cannot get it to play the second video at all , i cant tell whether it is resetting the videos button value or even calling the safetyvideo() function
i am at a loss now , i know the answer is staring at me but i just cant see it and dont yet understand enough to see what i am doing wrong.
any suggestions as to which part i am getting wrong would be really appreciated
int button = 3; //Define our button pin
int videos = 4; // buttons pin video if second video is one to play (safetyvideeo)
int buttonStatus = 1; //Sets the default button status
int playing = 0; //Defines whether or not the file is playing and sets it to NO.
int videoStatus = 1; // defines whether to play video 1 or 4, 1 - play video 1, 0 - play video 4
//1 is default setting after any video has played and eof command recieved.
void setup() {
Serial.begin(9600); //Start the serial connection that will communicate with the Sprite
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
}
void safetyVideo(){
if (buttonStatus == 0 && playing == 0){
playing = 1; //Set our playing variable to yes so when dont send two signals
Serial.write(0x04); //If the input voltage is 0, we send signal to the sprite to play file 004.xxx
videoStatus = 1); // reset videoStatus back to main movie selection ( default)
}
}
void mainMovie() {
if (buttonStatus == 0 && playing == 0){
playing = 1; //Set our playing variable to yes so when dont send two signals
Serial.write(0x01); //If the button or switch is flipped, we send signal to the sprite to play file 001.xxx
}
}
void loop() {
buttonStatus = digitalRead(button); //Reads whether or not our button or switch is flipped
videoStatus = digitalRead(videos); // reads video select button
if (videoStatus == 1) { // reads video select button
mainMovie(); //calls main video play function
}
if (videoStatus == 0) { // reads video select button
safetyVideo(); //calls safety video play function
}
if (Serial.read() == 0xEE && buttonStatus == 0 ){
playing = 1; // When the Sprite finishes a file it sends a finished signal so we use that to tell the arduino it is no longer playing a file.
}
while (buttonStatus != 1){ // check status of buttonStatus and do nothing if still 0
// do nothing except read it again
buttonStatus = digitalRead(button);
}
if (buttonStatus == 1){ // if crestron input is now high , set playing to 0
playing = 0;
}
}
I have now studied what is happening and realised that i may need to use the button to toggle the value of videoStatus, also i have noted that if the external voltage trigger is made low then pressing the button allows me to play the safety video , the rest of the code then seems to work.
The external trigger at startup is high , when the external system start button is pressed there is a delay before a relay drops out taking the buttonpress input low and causing the main video to play , so i am going to try toggling the videoState pushbutton to see if that has any effect on which video is triggered to play.