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.
HBridge.cpp
00001 #include "HBridge.h" 00002 00003 HBridge::HBridge(PinName pwm_pin, PinName min_1_pin, PinName min_2_pin, float pwm_period): pwm_pin_(pwm_pin), min_1_pin_(min_1_pin), min_2_pin_(min_2_pin) { 00004 pwm_pin_.period(pwm_period); 00005 } 00006 00007 //Input of -1 means full reverse, 1 means full forward 00008 //An input of magnitude > 1 gets reduced to 1 (or -1) by the pwm.write function 00009 void HBridge::set_output(float output) { 00010 this->output = output; 00011 if (output > 0) { 00012 min_1_pin_.write(0); 00013 min_2_pin_.write(1); 00014 pwm_pin_.write(0.5); 00015 } else if (output < 0) { 00016 min_1_pin_.write(1); 00017 min_2_pin_.write(0); 00018 pwm_pin_.write(0.5); 00019 } else { 00020 min_1_pin_.write(0); 00021 min_2_pin_.write(0); 00022 pwm_pin_.write(0.0); 00023 } 00024 } 00025 00026 void HBridge::forward() 00027 { 00028 min_1_pin_.write(1); 00029 min_2_pin_.write(0); 00030 pwm_pin_.write(0.5); 00031 } 00032 void HBridge::back() 00033 { 00034 min_1_pin_.write(0); 00035 min_2_pin_.write(1); 00036 pwm_pin_.write(0.5); 00037 00038 } 00039 void HBridge::initialize() 00040 { 00041 min_1_pin_.write(0); 00042 min_2_pin_.write(0); 00043 pwm_pin_.write(0); 00044 }
Generated on Tue Jul 12 2022 15:35:31 by
1.7.2