servo
Dependencies: Servo mbed tsi_sensor SLCD
Diff: main.cpp
- Revision:
- 1:854f2f39affd
- Parent:
- 0:f5fd64350b21
--- a/main.cpp Wed Mar 02 17:43:46 2016 +0000 +++ b/main.cpp Tue Mar 22 17:00:58 2016 +0000 @@ -1,21 +1,60 @@ -#include "mbed.h" + #include "mbed.h" #include "tsi_sensor.h" #include "Servo.h" +#include "SLCD.h" //для FRDM-46Z slider #define ELEC0 9 #define ELEC1 10 -DigitalOut gpo(D0); +//DigitalOut gpo(D0); +//DigitalOut gpo(D1); +//Servo myservo(D0); +SLCD slcd; +InterruptIn sw2(SW1); Servo myservo(D0); +PwmOut led(D1); +int Flag=0; +void sw2_release(void) +{ + Flag=1; +} + int main() { - PwmOut led(LED_GREEN); - TSIAnalogSlider tsi(ELEC0, ELEC1, 40); - + int angle =30; +// TSIAnalogSlider tsi(ELEC0, ELEC1, 40); + float delay1= 0.02f; + sw2.rise(&sw2_release); while (true) { - led = 1.0 - tsi.readPercentage(); - myservo=1.0- tsi.readPercentage(); - wait(0.2f); + for(int i=0; i<100;i++) + { + if(Flag) goto a1; + led = 1.0 - i/100; + for( int j=0; j<=angle; j++) + { + myservo.position((float)j); + wait(delay1); + } + + for( int j=angle; j>=-angle; j--) + { + myservo.position((float)j); + slcd.Home(); + slcd.printf("%d",j); + + wait(delay1); + } + for( int j=-angle; j<=0; j++) + { + myservo.position((float)j); + wait(delay1); + } + + } + } +a1: myservo.position(0.0f); + while (1){ + }; } \ No newline at end of file