Why won't tone() work

Have I gone mad?
This simple tone sketch will not compile.

void setup(){
}

void loop(){
  tone(8, 440, 1000);
  delay(1000);
  noTone(8);
  delay(500);
}

Error:

Tone.cpp.o: In function `loop':
C:\Arduino\arduino-1.0.5/Tone.ino:8: undefined reference to `tone(unsigned char, unsigned int, unsigned long)'
C:\Arduino\arduino-1.0.5/Tone.ino:10: undefined reference to `noTone(unsigned char)'

Because you've named your sketch "Tone" which is the name of a class in the library,
try naming it "tone_test" and see if it compiles...

[actually its not a class, but somehow the system has ignored Tone.cpp in the runtime
because your sketch is called Tone...]

Wow thanks MarkT,.
Renamed it to ToneTest and all is well.

Not a very well written IDE if one can't have a sketches name the same as a function.
Time to move over to UECIDE.

Time to move over to UECIDE.

Let us know what happens there, when you make the same mistake.

So UECIDE is no better in that regard?
Oh well.

The IDE produces a .cpp with the same name as the sketch.

Mark

holmes4:
The IDE produces a .cpp with the same name as the sketch.

Mark

Understood.

Read it and weep:


When the IDE does the compilation properly, like UECIDE does, it doesn't matter what you name your sketch, it still works. In UECIDE the core files are compiled separately into a libcore.a file and placed in a cache location (so it never has to compile it again for that board unless you change the core). Libraries are similarly compiled into libLibName.a files (libSPI.a, libEthernet.a, etc) and cached. Then your sketch is compiled, and linked properly (-lcore -lSPI -lEthernet etc) against those cached library files.