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.
Dependencies: mbed
Fork of motor_reverser by
main.cpp
00001 #include "mbed.h" 00002 Ticker reverser; 00003 00004 PwmOut motor_pwm(D5); 00005 DigitalOut dir(D4); 00006 00007 const int pwm_frequency = 10000; // PWM frequency 00008 const float duty_cycle = 1; // Duty cycle (half speed) 00009 bool direction = false; // Motor direction 00010 00011 const float reverse_frequency = 0.25; // Reversion frequency 00012 float reverse_period = 1/reverse_frequency; 00013 00014 void dirswitch(){ 00015 direction = !direction; // Reverse direction 00016 dir.write(direction); // Sending direction to pin 00017 } 00018 00019 int main() 00020 { 00021 reverser.attach(dirswitch, reverse_period); 00022 00023 dir.write(direction); // Write motor direction 00024 motor_pwm.period(1/pwm_frequency); // Motor PWM period 00025 motor_pwm.write(duty_cycle); // Set motor speed 00026 00027 while(true){ 00028 } 00029 00030 00031 }
Generated on Sat Jul 16 2022 21:28:49 by
1.7.2
