Go Down

Topic: Press a button on arduino to open a file? (Read 1 time) previous topic - next topic

demir57

Is it possible to have "processing" or another program monitor the serial port for when I press a button connected to an arduino to open a file and when i press another button to open another file? i am trying to get winamp to open different playlists for what button I press. If I can have the program make the computer think i double clicked on the playlist, winamp will automatically open it. I am using windows xp.
Thank you very much
Demir

BetaDelta

Check out firmata. This also sounds like a heavily processing based problem, so maybe check out their forum?

/me
"C++ : Where friends have access to your private members." - Gavin Russell Baker

MikMo

GoBetwino will do it - out of the box:

http://mikmo.dk/gobetwino.html

ckaos

or you could simply use the "open()" command in Processing :
http://processing.org/reference/open_.html

i do not know if winamp accepts commands though, but if it does, you could then simply use something like this:
String[] params = { "pathTowinamp/", "name of playlist or whatever param" };
open(params);



demir57

#4
Apr 17, 2009, 02:46 am Last Edit: Apr 17, 2009, 04:05 am by demir57 Reason: 1
I like the way gobetwino works. but i am having trouble setting up the code on my arduino. I am trying to make an Emergency Party Button
I am trying to set up the 3 switches to select what "level" the party should be. then by pressing the pushbutton switch sends the "level" by serial port to gobetwino which opens the playlist file i want to play.
this is the code i have so far i am new to programming i have some understanding but not much. so far the code i have just repeats the string "level1" over and over. how would i get it to stop after sending the string once? any help would be very appreciated.
Thanks

demir



Code: [Select]
/*
* Emergency Party Button
* Sends serial commands to the program gobetwino through serial port
*/

int inputPin1 = 5;               // sets the input pins
int inputPin2 = 6;
int inputPin3 = 7;
int inputPin4 = 8;
int val = 0;                    // variable for reading the pin status

void setup() {
 Serial.begin(9600);
 pinMode(inputPin1, INPUT);     // declares switches as input
 pinMode(inputPin2, INPUT);
 pinMode(inputPin3, INPUT);
 pinMode(inputPin4, INPUT);     // declares pushbutton as input
}

void loop(){
 val = digitalRead(inputPin1);  // read input value
 if (val == HIGH) {            // check if the input is HIGH
   Serial.println("LEVEL1");  // send command by serial port
 } else {
   
 }
}

MikMo

What kind of switch / button do you have wired up to pin 5 (Inputpin1) ?

And how is i hooked up ?

demir57

The first 3 inputs will be toggle switches, and the last will be a big red emergency stop button. they will be constantly on. they are connected like in the push button example on the arduino site with a pull up resistor.  http://www.arduino.cc/en/Tutorial/Button . I was also thinking about adding 2 keyed switches so there has to be at least 2 people to activate the highest level of "party mode" how would i program in a timmer so both keys must be turned within a second of each other? thanks very much for the help. if i could find some similar examples i could piece parts of code together but i am having difficulty finding what i need.
thanks
demir

MikMo

If you have pull up resistors then this statement in your code:

if (val == HIGH)

will always return true, unless the switch is pressed and connect the pin to ground.

I think it should be if (val == LOW)  

Could that be your problem ?

demir57

this is the current code i have. it sends the string to gobetwino when i press the button.but i get this error "The string recieved : 12345 is not a well formed command string" How would i fix that? also because i am using the delay at the end of the loop if i leave the toggle switch on it will send the string again after the delay. i am very sorry i am new to this im sure these are pretty easy questions for you guys. is there a good site i can go to to learn how to program better?
thanks
demir

Code: [Select]

/*
* Emergency Party Button
* Sends serial commands to the program gobetwino through serial port
*/

int inputPin1 = 5;               // sets the input pins
int inputPin2 = 6;
int inputPin3 = 7;
int inputPin4 = 8;
int val = 0;                    // variable for reading the pin status

void setup() {
 Serial.begin(9600);
 pinMode(inputPin1, INPUT);     // declares pushbuttons as input
 pinMode(inputPin2, INPUT);
 pinMode(inputPin3, INPUT);
 pinMode(inputPin4, INPUT);
}

void loop(){
 val = digitalRead(inputPin3);  // read input value
 if (val == HIGH) {            // check if the input is HIGH
   Serial.println("12345");  // send command by serial port
 delay(1000);
 }
}


MikMo

#9
Apr 19, 2009, 09:00 am Last Edit: Apr 19, 2009, 09:01 am by MikMo Reason: 1
read the GoBetwino documentation on how to format command strings.

The format depends on which command type you are trying to run.

Also check the sample Arduino sketches that comes with GoBetwino

demir57

Here is the current code. It is working perfectly. I only have 1 switch set up so far. how do i get the arduino to stop sending the string after the delay in the loop? i want to be able to leave the switch on but if i do the loop sends the command again and winamp starts playing the song from the beginning.
Code: [Select]
/*
* Emergency Party Button
* Sends serial commands to the program gobetwino through serial port
*/

int inputPin1 = 5;               // sets the input pins
int inputPin2 = 6;
int inputPin3 = 7;
int inputPin4 = 8;
int val = 0;                    // variable for reading the pin status

void setup() {
 Serial.begin(9600);
 pinMode(inputPin1, INPUT);     // declares pushbuttons as input
 pinMode(inputPin2, INPUT);
 pinMode(inputPin3, INPUT);
 pinMode(inputPin4, INPUT);
}

void loop(){
 val = digitalRead(inputPin3);  // read input value
 if (val == HIGH) {            // check if the input is HIGH
   Serial.println("#S|LEVEL1|[]#");  // send command by serial port
 delay(1000);
 }
}


FusiveResonance

Quote
. how do i get the arduino to stop sending the string after the delay in the loop? i want to be able to leave the switch on but if i do the loop sends the command again and winamp starts playing the song from the beginning.


Here's one way:

Code: [Select]
/*
* Emergency Party Button
* Sends serial commands to the program gobetwino through serial port
*/

int inputPin1 = 5;               // sets the input pins
int inputPin2 = 6;
int inputPin3 = 7;
int inputPin4 = 8;
int val = 0;                    // variable for reading the pin status

void setup() {
 Serial.begin(9600);
 pinMode(inputPin1, INPUT);     // declares pushbuttons as input
 pinMode(inputPin2, INPUT);
 pinMode(inputPin3, INPUT);
 pinMode(inputPin4, INPUT);
}

bool run_once = false;

void loop(){
 val = digitalRead(inputPin3);  // read input value
 
 if (val == HIGH && !run_once) {            // check if the input is HIGH and run_once == false
 }
     run_once = true;
   Serial.println("#S|LEVEL1|[]#");  // send command by serial port
 }
 delay(1000);
}



demir57

i have 3 switches set up to select the level 1,2 and 3. when the big red button is pressed that sends the level to gobetwino and it opens the playlist i want. The only problem i have now is that the "vallev" in my code is always "0" zero. how would i fix that? I am very sorry for the simple questions.
thanks
demir

Code: [Select]
/*
* Emergency Party Button
* Sends serial commands to the program gobetwino through serial port
*/

int inputPin1 = 5;               // sets the input pins
int inputPin2 = 6;
int inputPin3 = 7;
int inputPin4 = 8;
int vallev=0;                    //stores level value
int val = 0;                    // variable for reading the pin status

void setup() {
 Serial.begin(9600);
 pinMode(inputPin1, INPUT);     // declares pushbuttons as input
 pinMode(inputPin2, INPUT);
 pinMode(inputPin3, INPUT);
 pinMode(inputPin4, INPUT);
}

void loop(){
 val = digitalRead(inputPin1);  // read input value
 if (val == HIGH) {            // check if the input is HIGH
 vallev == 1;                   // send to vallev
 delay(1000);                  // delay to limit to 1 value per button press
 }
 val = digitalRead(inputPin2);  // read input value
 if (val == HIGH) {            // check if the input is HIGH
 vallev == 2;                   // send to vallev
 delay(1000);                  // delay to limit to 1 value per button press
 }
 val = digitalRead(inputPin3);  // read input value
 if (val == HIGH) {            // check if the input is HIGH
 vallev == 3;                   // send to vallev
 delay(1000);                  // delay to limit to 1 value per button press
 }
 
 val = digitalRead(inputPin4);  // read input value
 if (val == HIGH) {            // check if the input is HIGH
 Serial.print("#S|LEVEL");  // send command by serial port
 Serial.print(vallev);
 Serial.println("|[]#");    // Gobetwino intperets this as a single line
                           //looking like this "#S|LEVEL(vallev)|[]#"
 delay(1000);
 }
}


Coding Badly

vallev == 1;
...is a comparison

vallev = 1;
...is an assignment

demir57

Its working perfectly! hopefully this will be my final question for you guys. I want to set up 2 keyed switches at opposite ends of the room so there must be at least 2 people there to activate the highest party mode. how do i set up a timer so when it senses that both inputs go high within 1 second it activates the final level?
Thanks very much for your help you have been very informative.
Demir

Go Up