Go Down

Topic: Reading chars and storing into an array (!) (Read 608 times) previous topic - next topic

masterl1nk

Hi!
I'm playing with DTMF tones, using a MT8870 I decode tones to digital signals (binary code) and with some arduino code I parse it.

At this moment my loop function is:
Code: [Select]
void loop() {
irqState = digitalRead(STD); //Get the first trigger tone
if (irqState == 1) {
char code = mapKey();
Serial.println(code);
delay(100);
}
}


The thing is: I receive each decoded tone by triggering the irqState, So if I send 123 (three tones) I get 123, that is very nice!!! But now I want to 'store' it into an array to compare it later (to do some remote control stuff).

How can I do this?


Sorry for my english  :~

LarryD

#1
Jan 29, 2013, 04:27 am Last Edit: Jan 29, 2013, 04:41 am by LarryD Reason: 1
http://arduino.cc/en/Reference/Array
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html
Code: [Select]
//Lets say you have an array:
char dtmf [20]
int i = 0;

setup()
//some code

loop()
{
// some code
         irqState = digitalRead(STD);                //Get the first trigger tone
         if (irqState == 1)
         {    
               dtmf[++i]= mapKey();
               delay(100);
         }

// lets say an # starts iteration code thought dtmf[0] to dtmf[maximum] to process through the values
// don't forget to set i = 0 when you are ready to start capturing again.


} // END of loop

The way you have it in your schematic isn't the same as how you have it wired up!

PaulS

Code: [Select]
                dtmf[++i]= mapKey();
When i starts at 0, where are you storing the first value, Larry? Not in the 0 spot, where it belongs.

masterl1nk

Larry,
your solution works like a boss in my project, thanks!!!


lloyddean

#4
Jan 29, 2013, 11:42 pm Last Edit: Jan 29, 2013, 11:44 pm by lloyddean Reason: 1
I would think you'd want to start by placing the first item at 'dtmf[0]' and not 'dtmf[1]'

Try ...

Code: [Select]

dtmf[i++]= mapKey();


masterl1nk

Yep! I did that change to start in 0 position.

Thanks

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy