Piccolo / Mbed 2 deprecated piccolo

Dependencies:   mbed

Committer:
manuelitoys
Date:
Wed Sep 06 19:51:43 2017 +0000
Revision:
0:6155643a7318
prueba

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manuelitoys 0:6155643a7318 1 #include "mbed.h"
manuelitoys 0:6155643a7318 2 #define MAXPOS 255
manuelitoys 0:6155643a7318 3
manuelitoys 0:6155643a7318 4 PwmOut myServoX(PB_3);
manuelitoys 0:6155643a7318 5 PwmOut myServoY(PB_6);
manuelitoys 0:6155643a7318 6 PwmOut myServoZ(PB_4);
manuelitoys 0:6155643a7318 7
manuelitoys 0:6155643a7318 8
manuelitoys 0:6155643a7318 9 int coord2pulse(float coord)
manuelitoys 0:6155643a7318 10 {
manuelitoys 0:6155643a7318 11 if(0 <= coord <= MAXPOS)
manuelitoys 0:6155643a7318 12 return int(coord*1000/150+750);// us
manuelitoys 0:6155643a7318 13 return 750;
manuelitoys 0:6155643a7318 14
manuelitoys 0:6155643a7318 15 }
manuelitoys 0:6155643a7318 16 void draw(){
manuelitoys 0:6155643a7318 17 myServoY.pulsewidth_us(750);
manuelitoys 0:6155643a7318 18 }
manuelitoys 0:6155643a7318 19 void nodraw(){
manuelitoys 0:6155643a7318 20 myServoY.pulsewidth_us(2000);
manuelitoys 0:6155643a7318 21 }
manuelitoys 0:6155643a7318 22
manuelitoys 0:6155643a7318 23 void vertex2d(float x, float y){
manuelitoys 0:6155643a7318 24
manuelitoys 0:6155643a7318 25 int pulseX = coord2pulse(x);
manuelitoys 0:6155643a7318 26 int pulseY = coord2pulse(y);
manuelitoys 0:6155643a7318 27
manuelitoys 0:6155643a7318 28 myServoX.pulsewidth_us(pulseX);
manuelitoys 0:6155643a7318 29 myServoY.pulsewidth_us(pulseY);
manuelitoys 0:6155643a7318 30
manuelitoys 0:6155643a7318 31 }
manuelitoys 0:6155643a7318 32 void home()
manuelitoys 0:6155643a7318 33 {
manuelitoys 0:6155643a7318 34 vertex2d(0 ,0);
manuelitoys 0:6155643a7318 35 }
manuelitoys 0:6155643a7318 36
manuelitoys 0:6155643a7318 37 void maxpos()
manuelitoys 0:6155643a7318 38 {
manuelitoys 0:6155643a7318 39 vertex2d(MAXPOS ,MAXPOS);
manuelitoys 0:6155643a7318 40 }
manuelitoys 0:6155643a7318 41
manuelitoys 0:6155643a7318 42 int main() {
manuelitoys 0:6155643a7318 43 // configuracion de periodo
manuelitoys 0:6155643a7318 44 myServoX.period_ms(20);
manuelitoys 0:6155643a7318 45 myServoY.period_ms(20);
manuelitoys 0:6155643a7318 46 myServoZ.period_ms(20);
manuelitoys 0:6155643a7318 47
manuelitoys 0:6155643a7318 48 while(1)
manuelitoys 0:6155643a7318 49 {
manuelitoys 0:6155643a7318 50 draw();
manuelitoys 0:6155643a7318 51 wait(3);
manuelitoys 0:6155643a7318 52 home();
manuelitoys 0:6155643a7318 53 wait(3);
manuelitoys 0:6155643a7318 54 maxpos();
manuelitoys 0:6155643a7318 55 wait(3);
manuelitoys 0:6155643a7318 56 nodraw();
manuelitoys 0:6155643a7318 57 wait(3);
manuelitoys 0:6155643a7318 58
manuelitoys 0:6155643a7318 59 }
manuelitoys 0:6155643a7318 60
manuelitoys 0:6155643a7318 61 }
manuelitoys 0:6155643a7318 62