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.
main.cpp
00001 //NuMaker-PFM-NUC472 PWM0 output note to a speaker 00002 #include "mbed.h" 00003 00004 #define _C5 523 // C5 = 523.25Hz 00005 #define _D5 587 // D5 = 587.33Hz 00006 #define _E5 659 // E5 = 659.26Hz 00007 #define _F5 698 // F5 = 698.46Hz 00008 #define _G5 784 // G5 = 783.99Hz 00009 #define _A5 880 // A5 = 880.00Hz 00010 #define _B5 988 // B5 = 987.77Hz 00011 #define _C6 1046 // C6 = 1046.50Hz 00012 #define _D6 1175 // D6 = 1174.66Hz 00013 #define _E6 1319 // E6 = 1318.51Hz 00014 #define _F6 1397 // F6 = 1396.91Hz 00015 #define _G6 1568 // G6 = 1567.98Hz 00016 #define _A6 1760 // A6 = 1760.00Hz 00017 #define _B6 1976 // B6 = 1975.53Hz 00018 00019 #if defined(TARGET_NUMAKER_PFM_NUC472) 00020 PwmOut pwm0(PF_9); // PWM0 pin 00021 #elif defined(TARGET_NUMAKER_PFM_M453) 00022 PwmOut pwm0(PC_6); // PWM0_pin 00023 #elif defined(TARGET_NUMAKER_PFM_M487) 00024 PwmOut pwm0(PA_5); // PWM0_pin 00025 #endif 00026 00027 00028 int main() 00029 { 00030 int i =0; 00031 int note[15] = { // array of notes 00032 _C5, _D5, _E5, _F5, _G5, _A5, _B5, 00033 _C6, _D6, _E6, _F6, _G6, _A6, _B6}; 00034 00035 for (i=0; i<14; i++) { 00036 pwm0.period_us(1000000/note[i]); // set period per note 00037 pwm0.pulsewidth_us(1000000/note[i]/2); // set duty cycle to 50% 00038 Thread::wait(100); 00039 } 00040 pwm0.pulsewidth_us(0); // set dutycycle = 0% to stop 00041 }
Generated on Thu Jul 14 2022 12:24:48 by
1.7.2