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 #include "mbed.h" 00002 #include "TSISensor.h" 00003 00004 /** TSI_Cat 00005 * Test program for SG-90 00006 * PWM = Orange : D10 (PTD0) 00007 * Vcc = Red(+) : 5V 00008 * GND = Brown(-) : GND 00009 * 00010 * PWM Period : 20ms (50Hz) 00011 * Duty Cycle : 1 - 2 ms 00012 * Note: when I set pulsewidth from 1000us to 2000us 00013 * the servo did not move -90degree to 90degree 00014 * so I chanced the value from 500us to 3500us 00015 * by watching the movement. 00016 */ 00017 00018 TSISensor tsi ; 00019 PwmOut pwm(PTD0) ; // D10 00020 00021 int main() { 00022 float tsi_value ; 00023 pwm.period_ms(20) ; // 20ms period 00024 00025 while(1) { 00026 tsi_value = tsi.readPercentage() ; 00027 pwm.pulsewidth_us(500+ 3500*(tsi_value)) ; 00028 wait(0.01) ; 00029 } 00030 }
Generated on Fri Jul 22 2022 11:00:16 by
1.7.2