dhgdh
Dependencies: MAX44000 PWM_Tone_Library nexpaq_mdk
Fork of LED_Demo by
main.cpp
00001 #include "test_env.h" 00002 00003 /* Timer/Match Register Pinout Options 00004 00005 CT16B0/MR0 p5 (P0_9) 00006 CT16B0/MR1 p6 (P0_8) 00007 CT16B0/MR2 p34 (P1_15) 00008 00009 CT16B1/MR0 p36 (P0_21) 00010 CT16B1/MR1 p20 (P0_22) and p14 (P1_23) 00011 00012 CT32B0/MR0 p25 (P1_24) 00013 CT32B0/MR1 p26 (P1_25) and USBTX (P0_19) 00014 CT32B0/MR2 p10 (P1_26) 00015 */ 00016 00017 float value = 0.75; 00018 00019 int main() { 00020 #if defined(TARGET_FF_ARDUINO) 00021 PwmOut pwm(D9); 00022 int period_ms = 10; 00023 00024 pwm.period_ms(period_ms); 00025 pwm.write(value); 00026 00027 float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx 00028 printf("PWM period = %dms with duty cycle: %d%%\n", period_ms, (int) (result * 100)); 00029 00030 notify_completion(result == value ? true : false); 00031 #elif defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC2460) 00032 PwmOut pwm_p25(p25); 00033 PwmOut pwm_p26(p26); 00034 00035 pwm_p25.write(0.75); 00036 pwm_p26.write(0.50); 00037 00038 printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read()); 00039 printf("Initialize PWM on pin 26 with duty cycle: %.2f\n", pwm_p26.read()); 00040 00041 #elif defined(TARGET_LPC1114) 00042 PwmOut pwm_dp24(dp24); // P0_1 00043 PwmOut pwm_dp18(dp18); // P1_9 00044 00045 pwm_dp24.write(0.75); 00046 pwm_dp18.write(0.50); 00047 00048 printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_dp24.read()); 00049 printf("Initialize PWM on pin 18 with duty cycle: %.2f\n", pwm_dp18.read()); 00050 00051 #elif defined(TARGET_NRF51822) 00052 PwmOut pwm_p24(p24); 00053 PwmOut pwm_p25(p25); 00054 00055 pwm_p24.write(0.75); 00056 pwm_p25.write(0.50); 00057 00058 printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_p24.read()); 00059 printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read()); 00060 00061 #elif defined(TARGET_DISCO_F100RB) 00062 PwmOut pwm_1(PB_3); 00063 PwmOut pwm_2(PB_4); 00064 00065 pwm_1.write(0.75); 00066 pwm_2.write(0.50); 00067 00068 printf("Initialize PWM on pin PB_3 with duty cycle: %.2f\n", pwm_1.read()); 00069 printf("Initialize PWM on pin PB_4 with duty cycle: %.2f\n", pwm_2.read()); 00070 #elif defined(TARGET_DISCO_F051R8) 00071 PwmOut pwm_1(PA_7); 00072 PwmOut pwm_2(PC_7); 00073 00074 pwm_1.write(0.75); 00075 pwm_2.write(0.50); 00076 00077 printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read()); 00078 printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read()); 00079 #elif defined(TARGET_DISCO_F303VC) 00080 PwmOut pwm_1(PA_8); 00081 PwmOut pwm_2(PA_9); 00082 00083 pwm_1.write(0.75); 00084 pwm_2.write(0.50); 00085 00086 printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read()); 00087 printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read()); 00088 #elif defined(TARGET_MAXWSNENV) 00089 PwmOut pwm_1(TP2); 00090 PwmOut pwm_2(TP4); 00091 00092 pwm_1.write(0.75); 00093 pwm_2.write(0.50); 00094 00095 printf("Initialize PWM on pin TP2 with duty cycle: %.2f\n", pwm_1.read()); 00096 printf("Initialize PWM on pin TP4 with duty cycle: %.2f\n", pwm_2.read()); 00097 #elif defined(TARGET_DISCO_F407VG) 00098 PwmOut pwm_1(PD_12); 00099 PwmOut pwm_2(PD_13); 00100 00101 pwm_1.write(value); 00102 pwm_2.write(0.50); 00103 00104 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx 00105 00106 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result); 00107 printf("Initialize PWM on pin PD_13 with duty cycle: %.2f\n", pwm_2.read()); 00108 00109 notify_completion(result == value ? true : false); 00110 #elif defined(TARGET_DISCO_F429ZI) || defined(TARGET_NUCLEO_F429ZI) 00111 PwmOut pwm_1(PA_0); 00112 00113 pwm_1.write(value); 00114 00115 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx 00116 00117 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result); 00118 00119 notify_completion(result == value ? true : false); 00120 #elif defined(TARGET_MTS_MDOT_F405RG) 00121 PwmOut pwm_1(PA_0); 00122 00123 pwm_1.write(value); 00124 00125 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx 00126 00127 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result); 00128 00129 notify_completion(result == value ? true : false); 00130 #elif defined(TARGET_MTS_DRAGONFLY_F411RE) 00131 PwmOut pwm_1(PA_0); 00132 00133 pwm_1.write(value); 00134 00135 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx 00136 00137 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result); 00138 00139 notify_completion(result == value ? true : false); 00140 #elif defined(TARGET_MTS_MDOT_F411RE) 00141 PwmOut pwm_1(PA_0); 00142 00143 pwm_1.write(value); 00144 00145 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx 00146 00147 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result); 00148 00149 notify_completion(result == value ? true : false); 00150 #elif defined(TARGET_UBLOX_C029) 00151 PwmOut pwm_1(PA_0); 00152 00153 pwm_1.write(value); 00154 00155 float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx 00156 00157 printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result); 00158 00159 notify_completion(result == value ? true : false); 00160 #elif defined(TARGET_MAX32600MBED) 00161 PwmOut pwm_1(P1_2); 00162 PwmOut pwm_2(P1_3); 00163 00164 pwm_1.write(0.75); 00165 pwm_2.write(0.50); 00166 00167 printf("Initialize PWM on pin P1.2 with duty cycle: %.2f\n", pwm_1.read()); 00168 printf("Initialize PWM on pin P1.3 with duty cycle: %.2f\n", pwm_2.read()); 00169 #elif defined(TARGET_SAMR21G18A) || defined(TARGET_SAMD21J18A) || defined(TARGET_SAMD21G18A) || defined(TARGET_SAML21J18A) 00170 PwmOut pwm(LED1); 00171 00172 pwm.period_ms(1000); 00173 pwm.write(value); 00174 00175 float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx 00176 printf("Initialize PWM on pin LED1 with duty cycle: %.2f\n", result); 00177 00178 notify_completion(result == value ? true : false); 00179 #elif defined(TARGET_SAMG55J19) 00180 PwmOut pwm(PA00); /*LED Doesnt support PWM for G55 XPro*/ 00181 00182 pwm.period_ms(1000); 00183 pwm.write(value); 00184 00185 float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx 00186 printf("Initialize PWM on pin PA01 with duty cycle: %.2f\n", result); 00187 00188 notify_completion(result == value ? true : false); 00189 #else 00190 #error [NOT_SUPPORTED] This test is not supported on this target. 00191 #endif 00192 00193 notify_completion(true); 00194 }
Generated on Tue Jul 12 2022 11:01:54 by
1.7.2
