I'm new to Arduino, and I've been doing some minor projects from the project book. I'm currently working on the seventh project, the keyboard instruments, and I'm trying to enhance it. So far, I've added more notes, a volume control, a pitch pot and an arpeggio pot. I had to think really hard to get the arpeggio thing to work, but I was really happy when I found a way to make it work!
Anyway, my next idea is to add songs that will play when I press a single button, but typing each note is going to be a real hassle, so I've been trying to find a way not to have to type each "tone" variable. Is there a way to get something like "A4" being a short for:
tone (3, 440);
delay(100);
By the way, I know about the "pitches.h" library, but I wanted to try to make it work on my own!
And it defines the pitch of the note, but my problem is that I'd like to have both the pitch AND the lenth of the note in one keyword! Like A4h being a 440hz A half note, A4q being a 440hz A quarter note, etc...
This #define A4h tone(8, 440); delay(798); noTone(8); delay(2); is a macro.
When the pre processor sees "A4h" after this, it replaces the text "A4h" with the text in the macro.
That is macro expansion.
I searched, but I don't understand the explanations... As you subtly pointed out, I'm not a native english speaker, so understanding technical stuff like that is quite hard! That's why I'm asking questions here!