Add Speaker with 2 blinkers code

This commit is contained in:
coolneng 2019-11-08 18:50:13 +01:00
parent 175357d499
commit 613682d8cd
3 changed files with 531 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,246 @@
:100000000C945D000C9485000C9485000C94850084
:100010000C9485000C9485000C9485000C9485004C
:100020000C9485000C9485000C9485000C9485003C
:100030000C9485000C9485000C9485000C9485002C
:100040000C9482030C9485000C9450030C942A03A6
:100050000C9485000C9485000C9485000C9485000C
:100060000C9485000C94850000000008000201003B
:100070000003040700000000000000000000000072
:10008000250028002B0000000000240027002A0083
:10009000040404040404040402020202020203032E
:1000A0000303030301020408102040800102040836
:1000B0001020010204081020870411241FBECFEF76
:1000C000D8E0DEBFCDBF13E0A0E0B1E0E0E0FDE0AE
:1000D00002C005900D92A035B107D9F723E0A0E545
:1000E000B3E001C01D92A63FB207E1F710E0CDE5F5
:1000F000D0E004C02197FE010E946906CC35D107EB
:10010000C9F70E94CC030C947E060C94000090E08A
:10011000FC01EC55FF4F249180579F4FFC018491C7
:10012000882399F090E0880F991FFC01EA57FF4F50
:10013000A591B491FC01E458FF4F859194918FB73C
:10014000F894EC91E22BEC938FBF0895FC01538D52
:10015000448D252F30E0842F90E0821B930B5417A1
:1001600010F0CF96089501970895FC01918D828D2E
:10017000981761F0A28DAE0FBF2FB11D5D968C91C7
:10018000928D9F5F9F73928F90E008958FEF9FEF06
:100190000895FC01918D828D981731F0828DE80FC2
:1001A000F11D858D90E008958FEF9FEF0895FC017C
:1001B000918D228D892F90E0805C9F4F821B910949
:1001C0008F7399270895FC01A48DA80FB92FB11D35
:1001D000A35ABF4F2C91848D90E001968F7399277D
:1001E000848FA689B7892C93A089B1898C9183705B
:1001F00080648C93938D848D981306C00288F38954
:10020000E02D80818F7D80830895EF92FF920F9380
:100210001F93CF93DF93EC0181E0888F9B8D8C8DB2
:1002200098131AC0E889F989808185FF15C09FB7A6
:10023000F894EE89FF896083E889F9898081837069
:10024000806480839FBF81E090E0DF91CF911F9118
:100250000F91FF90EF900895F62E0B8D10E00F5F39
:100260001F4F0F731127E02E8C8D8E110CC00FB60F
:1002700007FCFACFE889F989808185FFF5CFCE01A7
:100280000E94E300F1CFEB8DEC0FFD2FF11DE35A3F
:10029000FF4FF0829FB7F8940B8FEA89FB8980812A
:1002A0008062CFCFCF93DF93EC01888D8823B9F0A4
:1002B000AA89BB89E889F9898C9185FD03C0808171
:1002C00086FD0DC00FB607FCF7CF8C9185FFF2CFEE
:1002D000808185FFEDCFCE010E94E300E9CFDF9161
:1002E000CF91089589E593E00E94D70021E0892B02
:1002F00009F420E0822F089580E090E0892B29F016
:100300000E94720181110C9400000895AF92BF9277
:10031000CF92DF92EF92FF920F931F93CF93DF93D1
:100320006C017B018B01040F151FEB015E01AE1800
:10033000BF08C017D10759F06991D601ED91FC9122
:100340000190F081E02DC6010995892B79F7C5014F
:10035000DF91CF911F910F91FF90EF90DF90CF90A1
:10036000BF90AF90089590E0FC01E859FF4F2491B1
:10037000FC01EC55FF4F3491FC01E057FF4FE49135
:10038000EE23C9F0222339F0233001F1A8F4213003
:1003900019F1223029F1F0E0EE0FFF1FE458FF4F72
:1003A000A591B4918FB7F894EC91611126C0309566
:1003B0003E233C938FBF08952730A9F02830C9F021
:1003C000243049F7809180008F7D03C080918000A8
:1003D0008F7780938000DFCF84B58F7784BDDBCFAC
:1003E00084B58F7DFBCF8091B0008F778093B00074
:1003F000D2CF8091B0008F7DF9CF3E2BDACF8F9294
:100400009F92AF92BF92CF92DF92EF92FF920F93A3
:100410001F93CF93DF934B015C0169017A0161E087
:100420008DE00E94B301A5019401C701B6010E94AD
:10043000E50528EE33E040E050E00E94090669013E
:100440007A0160E271EA87E090E0A50194010E94E0
:1004500009068901220F331F220F331FE901259757
:10046000812C912C54018C149D04AE04BF04D4F44F
:1004700061E088E00E94B3010230110518F0CE015E
:100480000197F1F760E088E00E94B30102301105A6
:1004900018F0CE010197F1F78FEF881A980AA80A91
:1004A000B80AE1CF60E08DE0DF91CF911F910F910D
:1004B000FF90EF90DF90CF90BF90AF909F908F9084
:1004C0000C94B3013FB7F894809155039091560373
:1004D000A0915703B091580326B5A89B05C02F3FA4
:1004E00019F00196A11DB11D3FBFBA2FA92F982F5A
:1004F0008827BC01CD01620F711D811D911D42E055
:10050000660F771F881F991F4A95D1F708958F921C
:100510009F92AF92BF92CF92DF92EF92FF926B01C8
:100520007C010E9462024B015C01C114D104E10410
:10053000F104B9F00E946202681979098A099B09DD
:10054000683E73408105910580F321E0C21AD1080D
:10055000E108F10888EE880E83E0981EA11CB11C0A
:10056000E4CFFF90EF90DF90CF90BF90AF909F903F
:100570008F900895CF93DF93FC0101900020E9F75D
:100580003197AF01481B590BBC0189E593E00E94EC
:100590008601EC0142E050E06AE273E089E593E015
:1005A0000E9486018C0F9D1FDF91CF910895AF921D
:1005B000BF92CF92DF92EF92FF920F931F93CF9350
:1005C000DF938DE293E00E94BA02CEE8D2E002EF20
:1005D00011E088EEA82E83E0B82E69917991C501CB
:1005E0000E94F5056B01770FEE08FF08F801619195
:1005F00071918F01072E000C880B990BA7019601B2
:100600000E94FF01C701B6010E94EC0426E636E60F
:1006100046EA5FE30E9450050E94B404072E000CD6
:10062000880B990B0E948702A701960160E070E099
:10063000CB010E94FF01F3E0CA32DF0771F6DF91C0
:10064000CF911F910F91FF90EF90DF90CF90BF90CF
:10065000AF9008951F920F920FB60F9211242F930F
:100660003F934F935F936F937F938F939F93AF933A
:10067000BF93EF93FF9389E593E00E94E300FF911E
:10068000EF91BF91AF919F918F917F916F915F910A
:100690004F913F912F910F900FBE0F901F90189583
:1006A0001F920F920FB60F9211242F938F939F9347
:1006B000EF93FF93E0916903F0916A038081E091E9
:1006C0006F03F091700382FD1BC0908180917203D3
:1006D0008F5F8F7320917303821741F0E091720353
:1006E000F0E0E75AFC4F958F80937203FF91EF91F2
:1006F0009F918F912F910F900FBE0F901F90189583
:100700008081F4CF1F920F920FB60F9211242F9376
:100710003F938F939F93AF93BF9380915103909199
:100720005203A0915303B09154033091500323E03E
:10073000230F2D3758F50196A11DB11D20935003AD
:100740008093510390935203A0935303B0935403A7
:100750008091550390915603A0915703B09158038F
:100760000196A11DB11D8093550390935603A0934C
:100770005703B0935803BF91AF919F918F913F91D1
:100780002F910F900FBE0F901F90189526E8230F02
:100790000296A11DB11DD2CF789484B5826084BD2C
:1007A00084B5816084BD85B5826085BD85B5816075
:1007B00085BD80916E00816080936E0010928100F3
:1007C00080918100826080938100809181008160AE
:1007D000809381008091800081608093800080916F
:1007E000B10084608093B1008091B00081608093FB
:1007F000B00080917A00846080937A0080917A00C2
:10080000826080937A0080917A00816080937A0080
:1008100080917A00806880937A001092C10088E00D
:100820000E9487008DE00E94870085E00E9487007B
:1008300088EEE82E83E0F82E90E0C92E90E0D92EC5
:100840000E94D7020E94D7028CE393E00E94BA0272
:10085000C2E8D1E002E111E069917991C7010E94FB
:10086000F5054B01770FAA08BB08F801619171915A
:100870008F01072E000C880B990BA50194010E9493
:10088000FF0161E08AE00E94B30164E670E080E06D
:1008900090E00E94870260E08AE00E94B30161E07C
:1008A00085E00E94B30164E670E080E090E00E9481
:1008B000870260E085E00E94B301C501B4010E9497
:1008C000EC0426E636E646EA5FE30E9450050E9405
:1008D000B404072E000C880B990B0E948702A50117
:1008E000940160E070E0CB010E94FF01F1E0C23FA3
:1008F000DF0709F0B1CFC114D10409F4A1CF0E94E0
:100900007201882309F49CCF0E94000099CFE9E589
:10091000F3E01382128288EE93E0A0E0B0E08483DB
:100920009583A683B78384E091E09183808385ECEF
:1009300090E09587848784EC90E09787868780ECA9
:1009400090E0918B808B81EC90E0938B828B82EC9A
:1009500090E0958B848B86EC90E0978B868B118E44
:10096000128E138E148E08950E94BB046894B111E8
:100970000C944A0508950E942F0588F09F5798F01F
:10098000B92F9927B751B0F0E1F0660F771F881F94
:10099000991F1AF0BA95C9F714C0B13091F00E94AE
:1009A0004905B1E008950C944905672F782F8827F1
:1009B000B85F39F0B93FCCF3869577956795B395D5
:1009C000D9F73EF490958095709561957F4F8F4F44
:1009D0009F4F0895E89409C097FB3EF49095809549
:1009E000709561957F4F8F4F9F4F9923A9F0F92FF5
:1009F00096E9BB279395F695879577956795B79573
:100A0000F111F8CFFAF4BB0F11F460FF1BC06F5F58
:100A10007F4F8F4F9F4F16C0882311F096E911C06A
:100A2000772321F09EE8872F762F05C0662371F08B
:100A300096E8862F70E060E02AF09A95660F771F9F
:100A4000881FDAF7880F9695879597F9089557FDCF
:100A50009058440F551F59F05F3F71F04795880F2C
:100A600097FB991F61F09F3F79F0879508951216C3
:100A700013061406551FF2CF4695F1DF08C016166F
:100A800017061806991FF1CF869571056105089420
:100A90000895E894BB2766277727CB0197F9089537
:100AA0000E9463050C94D4050E94C60538F00E948C
:100AB000CD0520F0952311F00C94BD050C94C305D1
:100AC00011240C944A050E94270570F3959FC1F3E9
:100AD000950F50E0551F629FF001729FBB27F00DEC
:100AE000B11D639FAA27F00DB11DAA1F649F662741
:100AF000B00DA11D661F829F2227B00DA11D621F90
:100B0000739FB00DA11D621F839FA00D611D221F49
:100B1000749F3327A00D611D231F849F600D211D2D
:100B2000822F762F6A2F11249F5750409AF0F1F0B0
:100B300088234AF0EE0FFF1FBB1F661F771F881F19
:100B400091505040A9F79E3F510580F00C94BD058F
:100B50000C944A055F3FE4F3983ED4F3869577956D
:100B60006795B795F795E7959F5FC1F7FE2B880FBF
:100B7000911D9695879597F9089597F99F6780E855
:100B800070E060E008959FEF80EC089500240A94DF
:100B90001616170618060906089500240A94121658
:100BA0001306140605060895092E0394000C11F48B
:100BB000882352F0BB0F40F4BF2B11F460FF04C038
:100BC0006F5F7F4F8F4F9F4F0895DB018F939F93F0
:100BD0000E942806BF91AF91A29F800D911DA39FF7
:100BE000900DB29F900D1124089597FB072E16F4D7
:100BF000009407D077FD09D00E94330607FC05D08A
:100C00003EF4909581959F4F0895709561957F4F23
:100C10000895052E97FB1EF400940E94200657FDB0
:100C200007D00E94470607FC03D04EF40C94200620
:100C300050954095309521953F4F4F4F5F4F089508
:100C400090958095709561957F4F8F4F9F4F089538
:100C50000E946F06A59F900DB49F900DA49F800DDC
:100C6000911D11240895AA1BBB1B51E107C0AA1FA7
:100C7000BB1FA617B70710F0A61BB70B881F991F3D
:100C80005A95A9F780959095BC01CD010895A1E2F0
:100C90001A2EAA1BBB1BFD010DC0AA1FBB1FEE1FF6
:100CA000FF1FA217B307E407F50720F0A21BB30B41
:100CB000E40BF50B661F771F881F991F1A9469F7BD
:100CC00060957095809590959B01AC01BD01CF0119
:100CD0000895EE0FFF1F0590F491E02D0994A29F57
:100CE000B001B39FC001A39F700D811D1124911D00
:100CF000B29F700D811D1124911D0895F894FFCFAE
:100D00000000000005018601A6005201D700B500D1
:100D1000C90006010B02DC00B801E900D2010000A5
:100D2000000006010B02DC00B801E900D20100005E
:100D30000000AF005D01930026019C003701000018
:100D40000000AF005D01930026019C003701000008
:100D50000000370115012601150137013701D000C8
:100D6000C4001501060172015D01A500D201B801A0
:100D70009F013701F700E900DC00D000000000000F
:100D800000000C000C000C000C000C000C00060015
:100D900003000C000C000C000C000C000C00060002
:100DA00003000C000C000C000C000C000C000600F2
:100DB00003000C000C000C000C000C000C000600E2
:100DC00006001200120012000600060006000600CF
:100DD000060006001200120012001200120012009B
:100DE0000A000A000A000A000A000A0003000300C1
:100DF00003004D0A4D0A00004D0A00002D084D0A5F
:100E00000000400C00000000000020060000000070
:100E100000002D080000000020060000000027054B
:100E200000000000E0060000B80700004907E006E7
:100E3000000020064D0A400CC00D0000EA0A400CDC
:100E400000004D0A00002D082D09B8070000000021
:100E50002D0800000000200600000000270500000B
:100E60000000E0060000B80700004907E0060000A7
:100E700020064D0A400CC00D0000EA0A400C00009C
:100E80004D0A00002D082D09B807000000000C00D5
:100E90000C000C000C000C000C000C000C000C00F2
:100EA0000C000C000C000C000C000C000C000C00E2
:100EB0000C000C000C000C000C000C000C000C00D2
:100EC0000C000C000C000C000C000C000C000900C5
:100ED000090009000C000C000C000C000C000C00B8
:100EE0000C000C000C000C000C000C000C000C00A2
:100EF0000C000C000C000C000C000C000C000C0092
:100F00000C000C000C000C000C000C000900090087
:100F100009000C000C000C000C000C000C000C0074
:100F20000C000C000C000C000C000D0A0020274DDA
:100F30006172696F205468656D6527002027556EC2
:100F4000646572776F726C64205468656D65270004
:00000001FF

285
Speaker/Speaker.ino Normal file
View File

@ -0,0 +1,285 @@
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#define melodyPin 8
//Mario main theme melody
int melody[] = {
NOTE_E7, NOTE_E7, 0, NOTE_E7,
0, NOTE_C7, NOTE_E7, 0,
NOTE_G7, 0, 0, 0,
NOTE_G6, 0, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
NOTE_G6, NOTE_E7, NOTE_G7,
NOTE_A7, 0, NOTE_F7, NOTE_G7,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0
};
//Mario main them tempo
int tempo[] = {
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
9, 9, 9,
12, 12, 12, 12,
12, 12, 12, 12,
12, 12, 12, 12,
};
//Underworld melody
int underworld_melody[] = {
NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
NOTE_AS3, NOTE_AS4, 0,
0,
NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
NOTE_AS3, NOTE_AS4, 0,
0,
NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
NOTE_DS3, NOTE_DS4, 0,
0,
NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
NOTE_DS3, NOTE_DS4, 0,
0, NOTE_DS4, NOTE_CS4, NOTE_D4,
NOTE_CS4, NOTE_DS4,
NOTE_DS4, NOTE_GS3,
NOTE_G3, NOTE_CS4,
NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
NOTE_GS4, NOTE_DS4, NOTE_B3,
NOTE_AS3, NOTE_A3, NOTE_GS3,
0, 0, 0
};
//Underwolrd tempo
int underworld_tempo[] = {
12, 12, 12, 12,
12, 12, 6,
3,
12, 12, 12, 12,
12, 12, 6,
3,
12, 12, 12, 12,
12, 12, 6,
3,
12, 12, 12, 12,
12, 12, 6,
6, 18, 18, 18,
6, 6,
6, 6,
6, 6,
18, 18, 18, 18, 18, 18,
10, 10, 10,
10, 10, 10,
3, 3, 3
};
void setup(void)
{
pinMode(8, OUTPUT);//buzzer
pinMode(13, OUTPUT);//led indicator when singing a note
pinMode(5, OUTPUT);
}
void loop()
{
//sing the tunes
int time = 100;
sing(1);
sing(1);
sing(2);
}
int song = 0;
void sing(int s) {
// iterate over the notes of the melody:
song = s;
if (song == 2) {
Serial.println(" 'Underworld Theme'");
int size = sizeof(underworld_melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / underworld_tempo[thisNote];
buzz(melodyPin, underworld_melody[thisNote], noteDuration);
blink(10, 100);
blink(5, 100);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
buzz(melodyPin, 0, noteDuration);
}
} else {
Serial.println(" 'Mario Theme'");
int size = sizeof(melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / tempo[thisNote];
buzz(melodyPin, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
buzz(melodyPin, 0, noteDuration);
}
}
}
void buzz(int targetPin, long frequency, long length) {
digitalWrite(13, HIGH);
long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
//// 1 second's worth of microseconds, divided by the frequency, then split in half since
//// there are two phases to each cycle
long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
//// multiply frequency, which is really cycles per second, by the number of seconds to
//// get the total number of cycles to produce
for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
delayMicroseconds(delayValue); // wait for the calculated delay value
digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
delayMicroseconds(delayValue); // wait again or the calculated delay value
}
digitalWrite(13, LOW);
}
void blink(int led, int time){
digitalWrite(led, HIGH);
delay(time);
digitalWrite(led, LOW);
}