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@0:050768391650, 2019-04-15 (annotated)
- Committer:
- Mateom0104
- Date:
- Mon Apr 15 05:59:01 2019 +0000
- Revision:
- 0:050768391650
control
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Mateom0104 | 0:050768391650 | 1 | #include "mbed.h" |
| Mateom0104 | 0:050768391650 | 2 | |
| Mateom0104 | 0:050768391650 | 3 | Serial pc(SERIAL_TX, SERIAL_RX); |
| Mateom0104 | 0:050768391650 | 4 | |
| Mateom0104 | 0:050768391650 | 5 | AnalogIn p1(A0); // entrada analoga potenciometro x |
| Mateom0104 | 0:050768391650 | 6 | AnalogIn p2(A1);// entrada analoga potenciometro y |
| Mateom0104 | 0:050768391650 | 7 | AnalogIn boton(A2);// entrada analoga boton |
| Mateom0104 | 0:050768391650 | 8 | |
| Mateom0104 | 0:050768391650 | 9 | float potx; //potenciometro en x |
| Mateom0104 | 0:050768391650 | 10 | float poty; // potenciometro en y |
| Mateom0104 | 0:050768391650 | 11 | float boton1; // boton |
| Mateom0104 | 0:050768391650 | 12 | |
| Mateom0104 | 0:050768391650 | 13 | |
| Mateom0104 | 0:050768391650 | 14 | DigitalOut led(LED1); |
| Mateom0104 | 0:050768391650 | 15 | |
| Mateom0104 | 0:050768391650 | 16 | void leer(void); |
| Mateom0104 | 0:050768391650 | 17 | |
| Mateom0104 | 0:050768391650 | 18 | int main() { |
| Mateom0104 | 0:050768391650 | 19 | pc.baud(9600); |
| Mateom0104 | 0:050768391650 | 20 | |
| Mateom0104 | 0:050768391650 | 21 | while(1) |
| Mateom0104 | 0:050768391650 | 22 | { |
| Mateom0104 | 0:050768391650 | 23 | leer(); |
| Mateom0104 | 0:050768391650 | 24 | while(boton1==1)// espera hasta que se levante el boton |
| Mateom0104 | 0:050768391650 | 25 | { |
| Mateom0104 | 0:050768391650 | 26 | leer(); |
| Mateom0104 | 0:050768391650 | 27 | if(boton1==0) // espera hasta precionar el boton |
| Mateom0104 | 0:050768391650 | 28 | led=!led; // prende y apaga led |
| Mateom0104 | 0:050768391650 | 29 | } |
| Mateom0104 | 0:050768391650 | 30 | } |
| Mateom0104 | 0:050768391650 | 31 | } |
| Mateom0104 | 0:050768391650 | 32 | |
| Mateom0104 | 0:050768391650 | 33 | |
| Mateom0104 | 0:050768391650 | 34 | void leer() |
| Mateom0104 | 0:050768391650 | 35 | { |
| Mateom0104 | 0:050768391650 | 36 | potx = p1.read(); // Lee potenciometr0 x, valores entre 0.0 y 1.0 |
| Mateom0104 | 0:050768391650 | 37 | pc.printf("%f ",potx); |
| Mateom0104 | 0:050768391650 | 38 | |
| Mateom0104 | 0:050768391650 | 39 | |
| Mateom0104 | 0:050768391650 | 40 | poty = p2.read(); // Lee potenciometro y, valores entre 0.0 y 1.0 |
| Mateom0104 | 0:050768391650 | 41 | pc.printf(" %f ",poty); |
| Mateom0104 | 0:050768391650 | 42 | |
| Mateom0104 | 0:050768391650 | 43 | boton1 = boton.read(); // Lee boton, valores entre 0.0 y 1.0 (valor<0.005 oprimido) |
| Mateom0104 | 0:050768391650 | 44 | pc.printf(" %f \n ",boton1); |
| Mateom0104 | 0:050768391650 | 45 | |
| Mateom0104 | 0:050768391650 | 46 | if (boton1<0.005) // si el valor es mas pe queño que 0.005 esa presionado |
| Mateom0104 | 0:050768391650 | 47 | boton1=0; |
| Mateom0104 | 0:050768391650 | 48 | else |
| Mateom0104 | 0:050768391650 | 49 | boton1=1; |
| Mateom0104 | 0:050768391650 | 50 | |
| Mateom0104 | 0:050768391650 | 51 | // wait(0.4); // si se quiere revisar valor leido por serial quietar comentario para q sea mas lento en el terminal |
| Mateom0104 | 0:050768391650 | 52 | |
| Mateom0104 | 0:050768391650 | 53 | } |