Motoo Tanaka / Mbed 2 deprecated TSI_Cat Featured

Dependencies:   TSI mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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 }