Pages: [1]   Go Down
Author Topic: Reading chars and storing into an array (!)  (Read 544 times)
0 Members and 1 Guest are viewing this topic.
Argentina
Offline Offline
Newbie
*
Karma: 1
Posts: 10
Web developer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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  smiley-confuse
Logged

Offline Offline
Faraday Member
**
Karma: 69
Posts: 2866
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Reference/Array
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html
Code:
//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
« Last Edit: January 28, 2013, 10:41:55 pm by LarryD » Logged

The way you have it in your schematic isn't the same as how you have it wired up! That goes for me too.

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 653
Posts: 50913
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Argentina
Offline Offline
Newbie
*
Karma: 1
Posts: 10
Web developer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would think you'd want to start by placing the first item at 'dtmf[0]' and not 'dtmf[1]'

Try ...

Code:
dtmf[i++]= mapKey();
« Last Edit: January 29, 2013, 05:44:54 pm by lloyddean » Logged

Argentina
Offline Offline
Newbie
*
Karma: 1
Posts: 10
Web developer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Thanks
Logged

Pages: [1]   Go Up
Jump to: