Pages: [1] 2   Go Down
Author Topic: Press a button on arduino to open a file?  (Read 1654 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Keynsham, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 224
I like for loops and walks on the beach,
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

/me
Logged

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

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

GoBetwino will do it - out of the box:

http://mikmo.dk/gobetwino.html
Logged

Paris, France
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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);


Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
/*
 * 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 {
    
  }
}
« Last Edit: April 16, 2009, 09:05:59 pm by demir57 » Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

And how is i hooked up ?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: April 19, 2009, 02:01:24 am by MikMo » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 175
---
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

vallev == 1;
...is a comparison

vallev = 1;
...is an assignment
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1] 2   Go Up
Jump to: