Tone Function Missing?

Hi

I’m a newbie… At least in the world of Arduino… So stick with me. I was going through some Arduino examples on the web and attempting to get them running on the Spark Core. One of them was playing sounds (agreed not necessarily essential but fun). The examples use the Tone() and noTone(). When I attempt to compile this on the web IDE I get

../be706443cd7acffa8ea2a9abe8d964e99b36e48df442641d6018afaa0bd2/the_user_app.cpp:16:30: error: 'tone' was not declared in this scope
../be706443cd7acffa8ea2a9abe8d964e99b36e48df442641d6018afaa0bd2/the_user_app.cpp:19:20: error: 'noTone' was not declared in this scope

Is this a missing library/function that hasn’t been ported or just something stupid I’m doing.

Thanks…

1 Like

Yup! You got it… I checked here http://docs.spark.io/#/firmware and there’s no Fun section. It’s all business… heh heh. I wouldn’t mind having tone() and noTone() functionality as well. It would probably come at the cost of losing a PWM output or two whenever you use tone() but that’s understandable.

If you use the delayMicroseconds() and direct port manipulation you might be able to roll your own for now though.

This might help if you want to play along… heh heh

CONSTANT	Freq (Hz)	Period (us)	Period/2 (us)
NOTE_B2		123		8130		4065
NOTE_C3		131		7634		3817
NOTE_CS3	139		7194		3597
NOTE_D3		147		6803		3401
NOTE_DS3	156		6410		3205
NOTE_E3		165		6061		3030
NOTE_F3		175		5714		2857
NOTE_FS3	185		5405		2703
NOTE_G3		196		5102		2551
NOTE_GS3	208		4808		2404
NOTE_A3		220		4545		2273
NOTE_AS3	233		4292		2146
NOTE_B3		247		4049		2024
NOTE_C4		262		3817		1908
NOTE_CS4	277		3610		1805
NOTE_D4		294		3401		1701
NOTE_DS4	311		3215		1608
NOTE_E4		330		3030		1515
NOTE_F4		349		2865		1433
NOTE_FS4	370		2703		1351
NOTE_G4		392		2551		1276
NOTE_GS4	415		2410		1205
NOTE_A4		440		2273		1136
NOTE_AS4	466		2146		1073
NOTE_B4		494		2024		1012
NOTE_C5		523		1912		956
NOTE_CS5	554		1805		903
NOTE_D5		587		1704		852
NOTE_DS5	622		1608		804
NOTE_E5		659		1517		759
NOTE_F5		698		1433		716
NOTE_FS5	740		1351		676
NOTE_G5		784		1276		638
NOTE_GS5	831		1203		602
NOTE_A5		880		1136		568
NOTE_AS5	932		1073		536
NOTE_B5		988		1012		506
NOTE_C6		1047		955		478
NOTE_CS6	1109		902		451
NOTE_D6		1175		851		426
NOTE_DS6	1245		803		402
NOTE_E6		1319		758		379
NOTE_F6		1397		716		358
NOTE_FS6	1480		676		338
NOTE_G6		1568		638		319
NOTE_GS6	1661		602		301
NOTE_A6		1760		568		284
NOTE_AS6	1865		536		268
NOTE_B6		1976		506		253
NOTE_C7		2093		478		239
NOTE_CS7	2217		451		226
NOTE_D7		2349		426		213
NOTE_DS7	2489		402		201
NOTE_E7		2637		379		190
NOTE_F7		2794		358		179
NOTE_FS7	2960		338		169
NOTE_G7		3136		319		159
NOTE_GS7	3322		301		151
NOTE_A7		3520		284		142
NOTE_AS7	3729		268		134
NOTE_B7		3951		253		127
NOTE_C8		4186		239		119
NOTE_CS8	4435		225		113
NOTE_D8		4699		213		106
NOTE_DS8	4978		201		100

And code defines:

#define NOTE_B2		4065
#define NOTE_C3		3817
#define NOTE_CS3	3597
#define NOTE_D3		3401
#define NOTE_DS3	3205
#define NOTE_E3		3030
#define NOTE_F3		2857
#define NOTE_FS3	2703
#define NOTE_G3		2551
#define NOTE_GS3	2404
#define NOTE_A3		2273
#define NOTE_AS3	2146
#define NOTE_B3		2024
#define NOTE_C4		1908
#define NOTE_CS4	1805
#define NOTE_D4		1701
#define NOTE_DS4	1608
#define NOTE_E4		1515
#define NOTE_F4		1433
#define NOTE_FS4	1351
#define NOTE_G4		1276
#define NOTE_GS4	1205
#define NOTE_A4		1136
#define NOTE_AS4	1073
#define NOTE_B4		1012
#define NOTE_C5		956
#define NOTE_CS5	903
#define NOTE_D5		852
#define NOTE_DS5	804
#define NOTE_E5		759
#define NOTE_F5		716
#define NOTE_FS5	676
#define NOTE_G5		638
#define NOTE_GS5	602
#define NOTE_A5		568
#define NOTE_AS5	536
#define NOTE_B5		506
#define NOTE_C6		478
#define NOTE_CS6	451
#define NOTE_D6		426
#define NOTE_DS6	402
#define NOTE_E6		379
#define NOTE_F6		358
#define NOTE_FS6	338
#define NOTE_G6		319
#define NOTE_GS6	301
#define NOTE_A6		284
#define NOTE_AS6	268
#define NOTE_B6		253
#define NOTE_C7		239
#define NOTE_CS7	226
#define NOTE_D7		213
#define NOTE_DS7	201
#define NOTE_E7		190
#define NOTE_F7		179
#define NOTE_FS7	169
#define NOTE_G7		159
#define NOTE_GS7	151
#define NOTE_A7		142
#define NOTE_AS7	134
#define NOTE_B7		127
#define NOTE_C8		119
#define NOTE_CS8	113
#define NOTE_D8		106
#define NOTE_DS8	100
1 Like

Added tone() and noTone() to the backlog. Thanks guys! As always, pull requests are welcome!

2 Likes

@Dom I couldn’t help myself… had to make this today:

Fun Category [ Check! ]

@BDub I’ll give it a go tonight.

Thanks

Works Great… Rick Rolling away… :smile:

@Dom Haha nice :slight_smile:

I JUST RICK ROLL’D MYSELF!!!
HAHAHAHA

you rock!

1 Like

Anyone interested can give this a try:
https://github.com/spark/core-firmware/blob/master/src/spark_wiring_tone.cpp

The implementation is based on Timer interrupts using Output Compare Toggle Mode of TIM peripherals. 10 timer mapped pins of the Core can be used to generate tones.

Heh, awesome. Back in the days of candybar and flip phones, I spent a lot of time transcribing music into RTTTL so that my wife and I could have custom ringtones without having to buy them at ridiculously inflated prices from our carrier. :smile: I might even still have my notes in the garage from when I did the Star Trek theme, Indiana Jones, and the Emperor’s March from Star Wars.

Cool, post 'em up over here if you can dig them out :smile: https://community.spark.io/t/a-remote-rtttl-ringtone-text-transfer-language-song-player/1149