coding error in uploading a tone on a toggle button

Hi everyone,

I am working on a project and most of it been completed but I am stuck on one thing . this is basically coding error. I am trying to play a tone on a speaker on arduino. I had played the tone on arduino only without the visual studio connectivity but now I am trying to control it from a toggle button from visual studio. but I think so there is a coding error here. Can anyone tell me what is the coding error and how can I fix it. Following are the code. I appreciate any effort from anyone in advance…Regards

#define NOTE_A3 220
#define NOTE_C4 262
#define NOTE_G3 196
#define NOTE_B3 247

int melody = {

int noteDurations = {
4, 8, 8, 4,4,4,4,4 };

void setup(){
pinMode(52, OUTPUT);

Serial.begin (9600);

void loop() {
{static boolean tone = false;
if (Serial.available()) {
int val = ();
if (val == ‘1’)
tone = true;
if (val == ‘0’)
tone = false;


if (tone) {digitalWrite(52,HIGH);
for (int thisNote = 0; thisNote < 35; thisNote++) {
int noteDuration = 1000/noteDurations[thisNote];
int pauseBetweenNotes = noteDuration * 1.30;

tone(52, melody[thisNote],noteDuration);



Please read this:-
How to use this forum
Because your post is breaking the rules about posting code.

You are using 'tone' as both a Boolean variable and a function you are calling, give the variable a different name.