Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of popcorn by
tetris.cpp
00001 #include "mbed.h" 00002 #include "beep.h" 00003 Beep buzzer(p23); 00004 00005 DigitalOut myled(LED1); 00006 00007 void play(char* note, char* length); 00008 00009 void tetris() { 00010 00011 00012 play("g", "Q"); 00013 play("d", "E"); 00014 play("eb", "E"); 00015 play("f", "Q"); 00016 play("eb", "E"); 00017 play("d", "E"); 00018 play("c", "Q"); 00019 play("c", "E"); 00020 play("eb", "E"); 00021 play("g", "Q"); 00022 play("f", "E"); 00023 play("eb", "E"); 00024 play("d", "T"); 00025 play("eb", "E"); 00026 play("f", "Q"); 00027 play("g", "Q"); 00028 play("eb", "S"); 00029 play("c", "S"); 00030 play("c", "S"); 00031 play("r", "Q"); 00032 play("r", "E"); 00033 play("f", "T"); 00034 play("abh", "E"); 00035 play("ch", "Q"); 00036 play("bbh", "E"); 00037 play("abh", "E"); 00038 play("g", "T"); 00039 play("eb", "E"); 00040 play("g", "Q"); 00041 play("f", "E"); 00042 play("eb", "E"); 00043 play("d", "Q"); 00044 play("d", "E"); 00045 play("eb", "E"); 00046 play("f", "Q"); 00047 play("g", "Q"); 00048 play("eb", "Q"); 00049 play("c", "S"); 00050 play("c", "S"); 00051 play("r", "Q"); 00052 00053 } 00054 00055 00056 void play(char* note, char* length) { 00057 00058 if (note=="ab") { 00059 buzzer.beepFreq(830); 00060 } 00061 if (note=="abh"){ 00062 buzzer.beepFreq(1661); 00063 } 00064 if (note=="bb") { 00065 buzzer.beepFreq(932); 00066 } 00067 if (note=="bbh") { 00068 buzzer.beepFreq(1865); 00069 } 00070 if (note=="c") { 00071 buzzer.beepFreq(1046); 00072 } 00073 if (note=="ch") { 00074 buzzer.beepFreq(2093); 00075 } 00076 if (note=="d") { 00077 buzzer.beepFreq(1175); 00078 } 00079 if (note=="eb") { 00080 buzzer.beepFreq(1245); 00081 } 00082 if (note=="f") { 00083 buzzer.beepFreq(1397); 00084 } 00085 if (note=="g") { 00086 buzzer.beepFreq(1568); 00087 } 00088 if (note=="r") { 00089 buzzer.beepFreq(0); 00090 } 00091 00092 if (length=="Q"){ //quarter note 00093 buzzer.beepTime(0.5); 00094 wait (0.5); 00095 } 00096 if (length=="E"){ // eighth note 00097 buzzer.beepTime(0.25); 00098 wait(0.25); 00099 } 00100 if (length=="T"){ //quarter+eigthh note 00101 buzzer.beepTime(0.75); 00102 wait(0.75); 00103 } 00104 if (length=="S"){ //staccato note 00105 buzzer.beepTime(0.25); 00106 wait(0.5); 00107 } 00108 00109 } 00110 00111 00112 int main() { 00113 tetris(); 00114 }
Generated on Tue Jul 12 2022 23:32:07 by
1.7.2
