We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi Processing Forum,
I am in the process of hacking a rotary phone, using Arduino and Processing to convert the phone into a recording and playback device. It is a really interesting project and I have made some progress, but I got stuck on a string from the serial port. My code is long, so I will share my public gist here: https://gist.github.com/lizzybrooks/b88531b906860d4fc4af.
Here is the function that seems to be giving me trouble:
void readNumbers(){
if ( myPort.available() > 0)
{
// get the value from the serial port
do{
val = myPort.readStringUntil('\n'); // read it and store it in val
} while (val == null);
// print every value received to the console so we know what we got
// println(val);
// println(val.length());
if (val.equals("6\r\n")){
println("hooray. you work. let's play a different audio file");
// anything else and its input from the phone
// so do whatever you want if you receive input from the phone here...
}
}
If you have any ideas or can help me with syntax, I would so much appreciate it. I am a beginner coder working on a complicated project, but I am eager to learn.
Thanks so much!
Lizzy
Answers
maybe
val=trim(val);
Hmm.. that didn't seem to make a difference. Maybe I am not adding it in the correct way? Here's the code now. It works up until the readNumbers function, which does not work.
The
val=trim(val);
line belongs at line 82, after there's a val to work with.You don't actually say what the trouble is.
What do you expect to happen?
and
What actually happens?
Hi, thanks for checking this out. I am trying to control a rotary phone with Processing, via Arduino. What I expect to happen is that the processing program reads the string val from the Arduino via the serial port.
If val is "dial tone", then the program plays an audio file. If the rotary dial is moving, the audio file pauses. If the phone's receiver is placed on the hook, the audio file pauses, and the program resets, enabling another dial tone. If val is "6", then the program prints "hooray. you work." Eventually I want to play a different audio file with the dialed number 6.
Everything works except val.equals("6"). I am able to send "6" from Arduino to Processing if I take away the rest of the code, but when I combine it with the other functions, "6" does not come through.
I am including code for both Arduino and Processing here. Thanks very much for taking a look!
Processing Code:
Arduino Code:
`
Hi dear thanks a lot of way. I am very happy know about Arduino you understood step by step. I knew already from robomart.com
In draw() you have
Assume that readSerial reads the String "6" and assume reset method does nothing. Now playTone() reads another string from the Serial port overriding the value "6" so by the time we get to dial() you read yet another string the chances are it isn't "6"
Only use readSerial to read the port into a variable. The other methods just act on the value of the variable and do not read the port.
The below code uses Arduino and Processing to turn a rotary phone into an audio recorder and playback machine. The Arduino program runs a loop, depending on inputs from the phone, and it sends strings to Processing to record and play audio files using the Minim player.
The code below is working to do the following: 1) play an operator's voice when the phone comes off the hook 2) record and play one track using the phone's receiver as a headset 3) stop recording or playing when the phone is hung up
Thanks for your help in previous threads. I just wanted to post the working code here in case anyone uses this.
Arduino code
Processing