Recognizing characters as constant name

Hi,

So I've been playing with notes lately and I'm trying to read notes from SD card and play them on the buzzer. So far, I've managed to read characters from SD card and properly separate them into notes. Now I'm trying to recognize those characters as a constant name from previosly defined note. So per example if I have:

#define C4 262

and I have variable that I got from my SD card:

char Note = 'C4';

How can I get another variable from it that is integer 262? I'm fairly new to programming so hopefully you can understand what am I trying to do here.

Please post your entire sketch if you have one.

This is incorrect, you can't assign a character string to a char, only a single character:

and I have variable that I got from my SD card:

char Note = 'C4';

A char string declaration looks like

char Note[] = "C4";

You say you have managed to read character strings from the SD, but it seems unlikely that you could have done it with this code...

On way to attack this would be to write a program that you could enter a line from the serial monitor that plays one note, probably with a duratoin.

Like…

c4 260 <<-- play C4 for 260 milliseconds.

or…

C4 50 260 << play c$ at 50% volume for 260 milliseconds.

Then take this to the point where you can paste in a block of notes and play them. By this time you should have a nice working parser that you could feed a SD card text file into that would play a tune.

Or not…

-jim lee

You could use brute force by putting the note strings in an array and the values in a second array in the same order. Read a note from the SD, iterate through the note array until a match is found then use the index of the found note string to extract the number from the second array then use it

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.