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.
Fork of 01-01SolucionFuncionXY by
main.cpp@4:29a8b1df7fe2, 2018-03-07 (annotated)
- Committer:
- fabeltranm
- Date:
- Wed Mar 07 00:43:55 2018 +0000
- Revision:
- 4:29a8b1df7fe2
- Parent:
- 3:fe8e265eaf6e
- Child:
- 5:9d27f2f6b1dc
init z
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| fabeltranm | 0:7ba873404776 | 1 | #include "mbed.h" |
| fabeltranm | 0:7ba873404776 | 2 | #define MAXPOS 50 // en milimetros |
| fabeltranm | 0:7ba873404776 | 3 | #define SS_TIME 100 // en microsegundos |
| fabeltranm | 3:fe8e265eaf6e | 4 | #define POSDRAW 10 |
| fabeltranm | 0:7ba873404776 | 5 | |
| fabeltranm | 0:7ba873404776 | 6 | PwmOut myServoX(PB_3); |
| fabeltranm | 0:7ba873404776 | 7 | PwmOut myServoY(PB_4); |
| fabeltranm | 3:fe8e265eaf6e | 8 | PwmOut myServoZ(PB_5); |
| fabeltranm | 0:7ba873404776 | 9 | |
| fabeltranm | 0:7ba873404776 | 10 | |
| fabeltranm | 3:fe8e265eaf6e | 11 | int coord2us(float coord) |
| fabeltranm | 3:fe8e265eaf6e | 12 | { |
| fabeltranm | 3:fe8e265eaf6e | 13 | if(0 <= coord <= MAXPOS) |
| fabeltranm | 3:fe8e265eaf6e | 14 | return int(750+coord*1900/50);// u6 |
| fabeltranm | 3:fe8e265eaf6e | 15 | return 750; |
| fabeltranm | 3:fe8e265eaf6e | 16 | |
| fabeltranm | 3:fe8e265eaf6e | 17 | } |
| fabeltranm | 3:fe8e265eaf6e | 18 | |
| fabeltranm | 2:878cb2697ab1 | 19 | void draw() |
| fabeltranm | 2:878cb2697ab1 | 20 | { |
| fabeltranm | 3:fe8e265eaf6e | 21 | myServoZ.pulsewidth_us(POSDRAW); |
| fabeltranm | 3:fe8e265eaf6e | 22 | wait(1); |
| fabeltranm | 2:878cb2697ab1 | 23 | } |
| fabeltranm | 2:878cb2697ab1 | 24 | void nodraw() |
| fabeltranm | 2:878cb2697ab1 | 25 | { |
| fabeltranm | 3:fe8e265eaf6e | 26 | myServoZ.pulsewidth_us(MAXPOS); |
| fabeltranm | 3:fe8e265eaf6e | 27 | wait(1); |
| fabeltranm | 2:878cb2697ab1 | 28 | } |
| fabeltranm | 0:7ba873404776 | 29 | void vertex2d(float x, float y){ |
| fabeltranm | 0:7ba873404776 | 30 | |
| fabeltranm | 3:fe8e265eaf6e | 31 | int pulseX = coord2us(x); |
| fabeltranm | 3:fe8e265eaf6e | 32 | int pulseY = coord2us(y); |
| fabeltranm | 0:7ba873404776 | 33 | |
| fabeltranm | 0:7ba873404776 | 34 | myServoX.pulsewidth_us(pulseX); |
| fabeltranm | 0:7ba873404776 | 35 | myServoY.pulsewidth_us(pulseY); |
| fabeltranm | 0:7ba873404776 | 36 | wait_ms(SS_TIME); |
| fabeltranm | 0:7ba873404776 | 37 | |
| fabeltranm | 0:7ba873404776 | 38 | } |
| fabeltranm | 0:7ba873404776 | 39 | |
| fabeltranm | 0:7ba873404776 | 40 | |
| fabeltranm | 3:fe8e265eaf6e | 41 | |
| fabeltranm | 0:7ba873404776 | 42 | int main() { |
| fabeltranm | 0:7ba873404776 | 43 | // configuracion de periodo |
| fabeltranm | 0:7ba873404776 | 44 | myServoX.period_ms(20); |
| fabeltranm | 0:7ba873404776 | 45 | myServoY.period_ms(20); |
| fabeltranm | 4:29a8b1df7fe2 | 46 | myServoZ.period_ms(20); |
| fabeltranm | 0:7ba873404776 | 47 | int posx=0; |
| fabeltranm | 0:7ba873404776 | 48 | int posy=0; |
| fabeltranm | 2:878cb2697ab1 | 49 | draw(); |
| fabeltranm | 0:7ba873404776 | 50 | while(1) |
| fabeltranm | 0:7ba873404776 | 51 | { |
| fabeltranm | 0:7ba873404776 | 52 | wait(2); |
| fabeltranm | 0:7ba873404776 | 53 | vertex2d(posx,posy); |
| fabeltranm | 0:7ba873404776 | 54 | posx+=10; |
| fabeltranm | 2:878cb2697ab1 | 55 | if (posx>50){ |
| fabeltranm | 2:878cb2697ab1 | 56 | posx=0; |
| fabeltranm | 2:878cb2697ab1 | 57 | nodraw(); |
| fabeltranm | 2:878cb2697ab1 | 58 | } |
| fabeltranm | 2:878cb2697ab1 | 59 | posy=posy; |
| fabeltranm | 0:7ba873404776 | 60 | } |
| fabeltranm | 0:7ba873404776 | 61 | |
| fabeltranm | 0:7ba873404776 | 62 | } |
| fabeltranm | 0:7ba873404776 | 63 |
