First Programme Error

Hi

im working through the kit book and have copied the sketch below but I cant seem to get it to work…

// melody

int speaker = 11;
int length = 15;
char notes = "ccggaagffeeddc ";
int beats = {1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4, };
int tempo =300;

void setup ()

{
pinMode(speaker, OUTPUT);
}

void loop ()

{
for (int i = 0; i < length; i++)
{
if (notes ==’’)

  • {*
    delay(beats * tempo);
    * }*
    * else*
    * {*
    playNote(notes, beats_ * tempo);
    * }
    delay(tempo / 2);
    }
    }
    void playTone(int tone, int duration)
    {
    for (long i = 0; i < duration * 1000L; i +=tone * 2)
    {
    digitalWrite(speaker, HIGH);
    delayMicroseconds (tone);
    digitalWrite (speaker, LOW);
    delayMicroseconds (tone);
    }
    }
    Void playNote(char note, int duration)
    {
    char names = {‘c’ ‘d’, ‘e’, ‘f’, ‘g’, ‘a’, ‘b’, ‘C’ };
    int tones = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
    for (int i = 0; i < 8; i++)
    {
    if (names == note)
    {
    playTone (tones, duration0;
    }
    }
    }
    [/quote]*

    these are the error messages im getting,
    melody.ino:20:20: error: empty character constant
    melody:7: error: ‘Void’ does not name a type
    melody.ino: In function ‘void loop()’:
    melody:26: error: ‘playNote’ was not declared in this scope
    melody.ino: At global scope:
    melody:43: error: ‘Void’ does not name a type
    can someone please explain the messages and I will try to fix the problem myself?
    many thanks
    A_
if (notes =='')

Empty, you say?

'Void' does not name a type

Quite right - "Void" does not name a type, but "void" does.

your code is riddled with syntax errors. You need to learn to read and understand the errors that the compiler is giving you.

When referring to an array, you need to include the index, i.e. if (notes*…)*
This code compiles:
```
*int speaker = 11;
int length = 15;
char notes = "ccggaagffeeddc ";
int beats = {1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4, 1};
int tempo =300;

void setup ()

{
  pinMode(speaker, OUTPUT);
}

void loop ()

{
  for (int i = 0; i < length; i++)
  {
    if (notes[i] ==’ ')
    {
      delay(beats[i] * tempo);
    }
    else
    {
      playNote(notes[i], beats[i] * tempo);
    }
    delay(tempo / 2);
  }
}

void playTone(int tone, int duration)
{
  for (long i = 0; i < duration * 1000L; i +=tone * 2)
  {
    digitalWrite(speaker, HIGH);
    delayMicroseconds (tone);
    digitalWrite (speaker, LOW);
    delayMicroseconds (tone);
  }
}

void playNote(char note, int duration)
{
  char names = {‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘a’, ‘b’, ‘C’ };
  int tones = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
  for (int i = 0; i < 8; i++)
  {
    if (names[i] == note)
    {
      playTone (tones[i], duration);
    }
  }
}*
```

thank you

solved the problems, guess my spelling and grammar need to improve a lot

// melody

int speaker = 11;
int length = 15;
char notes = "ccggaagffeeddc ";
int beats = {1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4,};
int tempo =300;

void setup ()

{
pinMode(speaker,OUTPUT);
}

void loop ()

{
for (int i = 0; i < length; i++)
{
if (notes ==‘1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4,’)

  • {*
    delay(beats * tempo);
    * }*
    * else*
    * {*
    playNote(notes, beats_ * tempo);
    * }
    delay(tempo / 2);
    }
    }
    void playTone(int tone, int duration)
    {
    for (long i = 0; i < duration * 1000L; i +=tone * 2)
    {
    digitalWrite(speaker, HIGH);
    delayMicroseconds (tone);
    digitalWrite (speaker, LOW);
    delayMicroseconds (tone);
    }
    }
    void playNote(char note, int duration)
    {
    char names = {‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘a’, ‘b’, ‘C’ };
    int tones = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
    for (int i = 0; i < 8; i++)
    {
    if (names == note)
    {
    playTone (tones, duration);
    }
    }
    }
    [/quote]*_

There's a really good reason we ask you to use code tags when posting code.
Can you see what it is?
(Hint: copy and paste the code in your quote in your last post into the IDE, and try to compile it.)