0
Offline
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« on: April 15, 2009, 06:18:08 pm » |
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
Full Member
Karma: 0
Posts: 224
I like for loops and walks on the beach,
|
 |
« Reply #1 on: April 15, 2009, 06:41:48 pm » |
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
Edison Member
Karma: 5
Posts: 2338
Do it !
|
 |
« Reply #2 on: April 16, 2009, 06:25:09 am » |
GoBetwino will do it - out of the box: http://mikmo.dk/gobetwino.html
|
|
|
|
|
Logged
|
|
|
|
|
Paris, France
Offline
Jr. Member
Karma: 0
Posts: 65
Arduino rocks
|
 |
« Reply #3 on: April 16, 2009, 01:40:21 pm » |
or you could simply use the "open()" command in Processing : http://processing.org/reference/open_.htmli 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
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #4 on: April 16, 2009, 07:46:55 pm » |
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 /* * 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
Edison Member
Karma: 5
Posts: 2338
Do it !
|
 |
« Reply #5 on: April 17, 2009, 06:03:18 am » |
What kind of switch / button do you have wired up to pin 5 (Inputpin1) ?
And how is i hooked up ?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #6 on: April 17, 2009, 05:07:17 pm » |
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
Edison Member
Karma: 5
Posts: 2338
Do it !
|
 |
« Reply #7 on: April 18, 2009, 12:43:16 am » |
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
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #8 on: April 18, 2009, 07:41:07 pm » |
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 /* * 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
Edison Member
Karma: 5
Posts: 2338
Do it !
|
 |
« Reply #9 on: April 19, 2009, 02:00:53 am » |
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
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #10 on: April 19, 2009, 01:23:24 pm » |
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. /* * 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
Full Member
Karma: 0
Posts: 175
---
|
 |
« Reply #11 on: April 19, 2009, 10:31:09 pm » |
. 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: /* * 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
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #12 on: April 21, 2009, 10:53:27 pm » |
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 /* * 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
Shannon Member
Karma: 116
Posts: 10130
|
 |
« Reply #13 on: April 22, 2009, 12:37:42 am » |
vallev == 1; ...is a comparison
vallev = 1; ...is an assignment
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 8
Arduino rocks
|
 |
« Reply #14 on: April 27, 2009, 07:17:00 pm » |
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
|
|
|
|
|
|