Skip to main content
deleted 1625 characters in body
Source Link

EDIT: The source code is have solved the Buzzer Play a Song oneproblem. It was missing the quotation marks around each letter. Thanks for your help, from this site: https://thinkershield.maas.museum/pcc-bronze/

My whole code:st2000!

//Code will play Pokemon theme song chorus when buzzer is pressed

/*defining notes and their frequencies
         note  frequency (Hz)*/

#define   c     //261
#define   d     //294
#define   e     //329
#define   f     //349
#define   g     //392
#define   a     //440
#define   b     //493
#define   C     //523
#define   D     //587
#define   E     //659
#define   F     //698

//notes to be played
void setup(){
  int melody[]={
    a,C,D, 
    a,a,C,D,D,C, 
    C,C,D,D,C, 
    C,D,E,F,E,D,C};

//note duration
int noteDuration[]={
  4, 4, 2,
  4, 4, 8, 1, 1, 1,
  4, 4, 1, 4, 4,
  4, 4, 4, 4, 4, 4, 1};
  }


//setup
int buzzer=3;
int button=7;

void setup() {
  
pinMode(buzzer, OUTPUT);
pinMode(button, INPUT);
}

void buzzerPlay()
{
  //calculating note duration by taking one second and dividing by the note type
  for(int thisNote=0; thisNote<(sizeof(melody)/sizeof(int))-1; thisNote++)
  {
    int noteDuration;
    if(thisNote<(sizeof(noteDurations)/sizeof(int))-1_
    {
      noteDuration=1000/noteDurations[thisNote];
    }
    else
    {
      noteDuration=1000;
    }
    tone(buzzer, melody[thisNote], noteDuration);
    //setting a time between notes
    int pause=noteDuration*1.30;
    delay(pause);
    noTone(buzzer);
  }
}

EDIT: The source code is the Buzzer Play a Song one, from this site: https://thinkershield.maas.museum/pcc-bronze/

My whole code:

//Code will play Pokemon theme song chorus when buzzer is pressed

/*defining notes and their frequencies
         note  frequency (Hz)*/

#define   c     //261
#define   d     //294
#define   e     //329
#define   f     //349
#define   g     //392
#define   a     //440
#define   b     //493
#define   C     //523
#define   D     //587
#define   E     //659
#define   F     //698

//notes to be played
void setup(){
  int melody[]={
    a,C,D, 
    a,a,C,D,D,C, 
    C,C,D,D,C, 
    C,D,E,F,E,D,C};

//note duration
int noteDuration[]={
  4, 4, 2,
  4, 4, 8, 1, 1, 1,
  4, 4, 1, 4, 4,
  4, 4, 4, 4, 4, 4, 1};
  }


//setup
int buzzer=3;
int button=7;

void setup() {
  
pinMode(buzzer, OUTPUT);
pinMode(button, INPUT);
}

void buzzerPlay()
{
  //calculating note duration by taking one second and dividing by the note type
  for(int thisNote=0; thisNote<(sizeof(melody)/sizeof(int))-1; thisNote++)
  {
    int noteDuration;
    if(thisNote<(sizeof(noteDurations)/sizeof(int))-1_
    {
      noteDuration=1000/noteDurations[thisNote];
    }
    else
    {
      noteDuration=1000;
    }
    tone(buzzer, melody[thisNote], noteDuration);
    //setting a time between notes
    int pause=noteDuration*1.30;
    delay(pause);
    noTone(buzzer);
  }
}

EDIT: have solved the problem. It was missing the quotation marks around each letter. Thanks for your help, st2000!

formatting code
Source Link
Kwasmich
  • 1.5k
  • 12
  • 18

//Code will play Pokemon theme song chorus when buzzer is pressed

/defining notes and their frequencies note frequency (Hz)/

#define c //261 #define d //294 #define e //329 #define f //349 #define g //392 #define a //440 #define b //493 #define C //523 #define D //587 #define E //659 #define F //698

//notes to be played void setup(){ int melody[]={ a,C,D, a,a,C,D,D,C, C,C,D,D,C, C,D,E,F,E,D,C};

//note duration int noteDuration[]={ 4, 4, 2, 4, 4, 8, 1, 1, 1, 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 1}; }

//setup int buzzer=3; int button=7;

void setup() {

pinMode(buzzer, OUTPUT); pinMode(button, INPUT); }

//Code will play Pokemon theme song chorus when buzzer is pressed

/*defining notes and their frequencies
         note  frequency (Hz)*/

#define   c     //261
#define   d     //294
#define   e     //329
#define   f     //349
#define   g     //392
#define   a     //440
#define   b     //493
#define   C     //523
#define   D     //587
#define   E     //659
#define   F     //698

//notes to be played
void setup(){
  int melody[]={
    a,C,D, 
    a,a,C,D,D,C, 
    C,C,D,D,C, 
    C,D,E,F,E,D,C};

//note duration
int noteDuration[]={
  4, 4, 2,
  4, 4, 8, 1, 1, 1,
  4, 4, 1, 4, 4,
  4, 4, 4, 4, 4, 4, 1};
  }


//setup
int buzzer=3;
int button=7;

void setup() {
  
pinMode(buzzer, OUTPUT);
pinMode(button, INPUT);
}

void buzzerPlay()
{
  //calculating note duration by taking one second and dividing by the note type
  for(int thisNote=0; thisNote<(sizeof(melody)/sizeof(int))-1; thisNote++)
  {
    int noteDuration;
    if(thisNote<(sizeof(noteDurations)/sizeof(int))-1_
    {
      noteDuration=1000/noteDurations[thisNote];
    }
    else
    {
      noteDuration=1000;
    }
    tone(buzzer, melody[thisNote], noteDuration);
    //setting a time between notes
    int pause=noteDuration*1.30;
    delay(pause);
    noTone(buzzer);
  }
}

void buzzerPlay() { //calculating note duration by taking one second and dividing by the note type for(int thisNote=0; thisNote<(sizeof(melody)/sizeof(int))-1; thisNote++) { int noteDuration; if(thisNote<(sizeof(noteDurations)/sizeof(int))-1_ { noteDuration=1000/noteDurations[thisNote]; } else { noteDuration=1000; } tone(buzzer, melody[thisNote], noteDuration); //setting a time between notes int pause=noteDuration*1.30; delay(pause); noTone(buzzer); } }

 

int melody[]={ a,C,D, a,a,C,D,D,C, C,C,D,D,C, C,D,E,F,E,D,C};

  int melody[]={
    a,C,D, 
    a,a,C,D,D,C, 
    C,C,D,D,C, 
    C,D,E,F,E,D,C};

//Code will play Pokemon theme song chorus when buzzer is pressed

/defining notes and their frequencies note frequency (Hz)/

#define c //261 #define d //294 #define e //329 #define f //349 #define g //392 #define a //440 #define b //493 #define C //523 #define D //587 #define E //659 #define F //698

//notes to be played void setup(){ int melody[]={ a,C,D, a,a,C,D,D,C, C,C,D,D,C, C,D,E,F,E,D,C};

//note duration int noteDuration[]={ 4, 4, 2, 4, 4, 8, 1, 1, 1, 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 1}; }

//setup int buzzer=3; int button=7;

void setup() {

pinMode(buzzer, OUTPUT); pinMode(button, INPUT); }

void buzzerPlay() { //calculating note duration by taking one second and dividing by the note type for(int thisNote=0; thisNote<(sizeof(melody)/sizeof(int))-1; thisNote++) { int noteDuration; if(thisNote<(sizeof(noteDurations)/sizeof(int))-1_ { noteDuration=1000/noteDurations[thisNote]; } else { noteDuration=1000; } tone(buzzer, melody[thisNote], noteDuration); //setting a time between notes int pause=noteDuration*1.30; delay(pause); noTone(buzzer); } }

int melody[]={ a,C,D, a,a,C,D,D,C, C,C,D,D,C, C,D,E,F,E,D,C};

//Code will play Pokemon theme song chorus when buzzer is pressed

/*defining notes and their frequencies
         note  frequency (Hz)*/

#define   c     //261
#define   d     //294
#define   e     //329
#define   f     //349
#define   g     //392
#define   a     //440
#define   b     //493
#define   C     //523
#define   D     //587
#define   E     //659
#define   F     //698

//notes to be played
void setup(){
  int melody[]={
    a,C,D, 
    a,a,C,D,D,C, 
    C,C,D,D,C, 
    C,D,E,F,E,D,C};

//note duration
int noteDuration[]={
  4, 4, 2,
  4, 4, 8, 1, 1, 1,
  4, 4, 1, 4, 4,
  4, 4, 4, 4, 4, 4, 1};
  }


//setup
int buzzer=3;
int button=7;

void setup() {
  
pinMode(buzzer, OUTPUT);
pinMode(button, INPUT);
}

void buzzerPlay()
{
  //calculating note duration by taking one second and dividing by the note type
  for(int thisNote=0; thisNote<(sizeof(melody)/sizeof(int))-1; thisNote++)
  {
    int noteDuration;
    if(thisNote<(sizeof(noteDurations)/sizeof(int))-1_
    {
      noteDuration=1000/noteDurations[thisNote];
    }
    else
    {
      noteDuration=1000;
    }
    tone(buzzer, melody[thisNote], noteDuration);
    //setting a time between notes
    int pause=noteDuration*1.30;
    delay(pause);
    noTone(buzzer);
  }
}
 
  int melody[]={
    a,C,D, 
    a,a,C,D,D,C, 
    C,C,D,D,C, 
    C,D,E,F,E,D,C};
added 1490 characters in body
Source Link

EDIT: The source code is the Buzzer Play a Song one, from this site: https://thinkershield.maas.museum/pcc-bronze/

My whole code:

//Code will play Pokemon theme song chorus when buzzer is pressed

/defining notes and their frequencies note frequency (Hz)/

#define c //261 #define d //294 #define e //329 #define f //349 #define g //392 #define a //440 #define b //493 #define C //523 #define D //587 #define E //659 #define F //698

//notes to be played void setup(){ int melody[]={ a,C,D, a,a,C,D,D,C, C,C,D,D,C, C,D,E,F,E,D,C};

//note duration int noteDuration[]={ 4, 4, 2, 4, 4, 8, 1, 1, 1, 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 1}; }

//setup int buzzer=3; int button=7;

void setup() {

pinMode(buzzer, OUTPUT); pinMode(button, INPUT); }

void buzzerPlay() { //calculating note duration by taking one second and dividing by the note type for(int thisNote=0; thisNote<(sizeof(melody)/sizeof(int))-1; thisNote++) { int noteDuration; if(thisNote<(sizeof(noteDurations)/sizeof(int))-1_ { noteDuration=1000/noteDurations[thisNote]; } else { noteDuration=1000; } tone(buzzer, melody[thisNote], noteDuration); //setting a time between notes int pause=noteDuration*1.30; delay(pause); noTone(buzzer); } }

I am very new to Arduino and C++ (coding in general!). Have copied an example code, only modifying the notes to make my own tune. But when I click 'verify', I am getting the error above, and I can't for the life of me, work out what is wrong! I've searched and read several forums and FAQs, but am just coming up blank. This is the code I have, where the error is occuring:

int melody[]={ a,C,D, a,a,C,D,D,C, C,C,D,D,C, C,D,E,F,E,D,C};

Any help would be greatly appreciated!

I am very new to Arduino and C++ (coding in general!). Have copied an example code, only modifying the notes to make my own tune. But when I click 'verify', I am getting the error above, and I can't for the life of me, work out what is wrong! I've searched and read several forums and FAQs, but am just coming up blank. This is the code I have, where the error is occuring:

int melody[]={ a,C,D, a,a,C,D,D,C, C,C,D,D,C, C,D,E,F,E,D,C};

Any help would be greatly appreciated!

EDIT: The source code is the Buzzer Play a Song one, from this site: https://thinkershield.maas.museum/pcc-bronze/

My whole code:

//Code will play Pokemon theme song chorus when buzzer is pressed

/defining notes and their frequencies note frequency (Hz)/

#define c //261 #define d //294 #define e //329 #define f //349 #define g //392 #define a //440 #define b //493 #define C //523 #define D //587 #define E //659 #define F //698

//notes to be played void setup(){ int melody[]={ a,C,D, a,a,C,D,D,C, C,C,D,D,C, C,D,E,F,E,D,C};

//note duration int noteDuration[]={ 4, 4, 2, 4, 4, 8, 1, 1, 1, 4, 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 1}; }

//setup int buzzer=3; int button=7;

void setup() {

pinMode(buzzer, OUTPUT); pinMode(button, INPUT); }

void buzzerPlay() { //calculating note duration by taking one second and dividing by the note type for(int thisNote=0; thisNote<(sizeof(melody)/sizeof(int))-1; thisNote++) { int noteDuration; if(thisNote<(sizeof(noteDurations)/sizeof(int))-1_ { noteDuration=1000/noteDurations[thisNote]; } else { noteDuration=1000; } tone(buzzer, melody[thisNote], noteDuration); //setting a time between notes int pause=noteDuration*1.30; delay(pause); noTone(buzzer); } }

I am very new to Arduino and C++ (coding in general!). Have copied an example code, only modifying the notes to make my own tune. But when I click 'verify', I am getting the error above, and I can't for the life of me, work out what is wrong! I've searched and read several forums and FAQs, but am just coming up blank. This is the code I have, where the error is occuring:

int melody[]={ a,C,D, a,a,C,D,D,C, C,C,D,D,C, C,D,E,F,E,D,C};

Any help would be greatly appreciated!

Source Link
Loading