2-pole with spin-up from approx 5 Hz.. no manual control added yet
Dependencies: mbed-STM32F103C8T6 mbed-rtos mbed
main.cpp
00001 #include "stm32f103c8t6.h" 00002 #include "mbed.h" 00003 #include "rtos.h" 00004 00005 PwmOut mypwmled(PB_10); 00006 double per; 00007 DigitalOut myled(LED1); 00008 AnalogIn sensepwm(PB_1); 00009 00010 00011 void q_bar() { 00012 while (1) { 00013 if (sensepwm.read() > 0.45) { // If the value is greater than 2V then toggle the LED 00014 myled = 1; 00015 } 00016 else { 00017 myled = 0; 00018 } 00019 00020 00021 } 00022 } 00023 00024 int main() { 00025 mypwmled = 0.5; 00026 mypwmled.period_ms(1000); 00027 per = 1000; 00028 Thread thread(q_bar); 00029 while(per>40) { 00030 00031 00032 mypwmled.period_us(per*1000); 00033 //printf("LED is now %.2f\n", led.read()); 00034 00035 wait_ms(per*2+100); 00036 per = per - 20; 00037 00038 } 00039 00040 while (1) { 00041 while(per<100) { 00042 00043 00044 mypwmled.period_us(per*1000); 00045 //printf("LED is now %.2f\n", led.read()); 00046 00047 wait_ms(per*2+100); 00048 per = per + 3; 00049 00050 } 00051 while(per>40) { 00052 00053 00054 mypwmled.period_us(per*1000); 00055 //printf("LED is now %.2f\n", led.read()); 00056 00057 wait_ms(per*3+100); 00058 per = per - 3; 00059 00060 } 00061 } 00062 00063 per = 1000; 00064 mypwmled.period_us(per*1000); 00065 00066 }
Generated on Thu Jul 28 2022 18:42:59 by 1.7.2