data types in C

Hi there,

My Arduino came today and I started doing the examples.
Now I´m doing a melody (which I copied from youtube) - All my little ducklings.
Everything works which is nice. But I wonder if I could replace a data typ with a shorter string.

So for example: Instead of NOTE_C4 I just want to write c4.

Sorry for such a basic question. Just had one semester of python, never learned C.

Thank you :slight_smile:

Here is the code:

 #include "pitches.h"

// notes in the melody:

 int melody[] = {
// note durations: 4 = quarter note, 8 = eighth note, etc.:
 int noteDurations[] = {
void setup() {
   // iterate over the notes of the melody:
   for (int thisNote = 0; thisNote < 27; thisNote++) {
    // to calculate the note duration, take one second
    // divided by the note type.
     //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
     int noteDuration = 1000/noteDurations[thisNote];
     tone(12, melody[thisNote],noteDuration);
    // to distinguish the notes, set a minimum time between them.
     // the note's duration + 30% seems to work well:
     int pauseBetweenNotes = noteDuration * 1.30;
     // stop the tone playing:
void loop() {

You may have noticed the #included file pitches.h at the top of your sketch... That's where the definitions for each note are created. - e.g.

#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46


If you want to create different (or non-standard) notations, feel free to edit that file -OR PREFERABLY- copy that file to myPitches.h or similar, and rename the notes to somethig you prefer - taking care not to create invalid or conflicting names.

Good luck & happy learning!

Instead of NOTE_C4 I just want to write c4.

You can replace the original with any unique name (symbol). Case matters, C4 is not the same as c4.

Keep in mind that lots of similar symbols, like A0, A1, ... A7 are reserved for Arduino and the microprocessor.