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 VOLTIMETRO1 by
main.cpp@4:ebe7948a209e, 2017-12-01 (annotated)
- Committer:
- Christianh
- Date:
- Fri Dec 01 14:36:25 2017 +0000
- Revision:
- 4:ebe7948a209e
- Parent:
- 3:61fd3a58c5bf
2input
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| tony63 | 1:d0a4ddc1bd88 | 1 | //programa para enviar valores analogos y probarlos con app inventor |
| tony63 | 1:d0a4ddc1bd88 | 2 | //el programa en esta oportunidad manda valores provenientes del puero analogico en |
| tony63 | 1:d0a4ddc1bd88 | 3 | //enteros HEX (xxxx) entre 0 y 1000 |
| Christianh | 4:ebe7948a209e | 4 | //se prueba con voltimetro1 .apk APPINVENTOR. cambie bt A pc si quere probar directo sobre la pc |
| tony63 | 0:4676a90107ca | 5 | |
| tony63 | 0:4676a90107ca | 6 | #include "mbed.h" |
| tony63 | 1:d0a4ddc1bd88 | 7 | #include <stdio.h> |
| tony63 | 1:d0a4ddc1bd88 | 8 | //#include <conio.h> |
| Christianh | 4:ebe7948a209e | 9 | DigitalOut ledA (LED1); |
| Christianh | 4:ebe7948a209e | 10 | DigitalOut ledR (LED2); |
| Christianh | 4:ebe7948a209e | 11 | DigitalOut ledV (LED3); |
| tony63 | 1:d0a4ddc1bd88 | 12 | |
| Christianh | 4:ebe7948a209e | 13 | Serial bt(PTE0,PTE1); //puertos el bluetooth tx rx |
| tony63 | 0:4676a90107ca | 14 | Serial pc(USBTX,USBRX); |
| kolive360 | 3:61fd3a58c5bf | 15 | int med,num1,num2,i,j,k; |
| Christianh | 4:ebe7948a209e | 16 | AnalogIn input1(A4); //Pot1 |
| Christianh | 4:ebe7948a209e | 17 | AnalogIn input2(A5); //Pot2 |
| Christianh | 4:ebe7948a209e | 18 | |
| Christianh | 4:ebe7948a209e | 19 | |
| Christianh | 4:ebe7948a209e | 20 | |
| tony63 | 1:d0a4ddc1bd88 | 21 | |
| Christianh | 4:ebe7948a209e | 22 | int main(void){ |
| Christianh | 4:ebe7948a209e | 23 | |
| Christianh | 4:ebe7948a209e | 24 | ledA=1; |
| Christianh | 4:ebe7948a209e | 25 | ledR=1; |
| Christianh | 4:ebe7948a209e | 26 | ledV=1; |
| Christianh | 4:ebe7948a209e | 27 | ledA=0; |
| Christianh | 4:ebe7948a209e | 28 | |
| Christianh | 4:ebe7948a209e | 29 | |
| Christianh | 4:ebe7948a209e | 30 | bt.baud(9600); // asigno baudios y configuro puerto serie de la usart |
| Christianh | 4:ebe7948a209e | 31 | bt.format(8,Serial::None,1); |
| tony63 | 1:d0a4ddc1bd88 | 32 | |
| Christianh | 4:ebe7948a209e | 33 | while(1){ //leo puerto analogico los potenciometros |
| Christianh | 4:ebe7948a209e | 34 | wait(0.5); //tiempo entre lecturas |
| Christianh | 4:ebe7948a209e | 35 | |
| Christianh | 4:ebe7948a209e | 36 | num1 = input1*1000; //agrando el numero de cero a mil |
| Christianh | 4:ebe7948a209e | 37 | num2 = input1*1000; //agrando el numero de cero a mil |
| kolive360 | 3:61fd3a58c5bf | 38 | |
| kolive360 | 3:61fd3a58c5bf | 39 | |
| Christianh | 4:ebe7948a209e | 40 | if(num1<256){ //debo generar dos casos a APP inventor solo me recibe hex asi: 0xhhhh (4 cifras) |
| Christianh | 4:ebe7948a209e | 41 | bt.putc(0); //si el numero es hasta 255 se le ponen dos ceros adelante a la secuencia de bits |
| Christianh | 4:ebe7948a209e | 42 | bt.putc(num1); //luego la cifra menos significativa |
| Christianh | 4:ebe7948a209e | 43 | pc.printf("vol 1\n"); |
| Christianh | 4:ebe7948a209e | 44 | pc.printf("%i",num1); |
| Christianh | 4:ebe7948a209e | 45 | } |
| Christianh | 4:ebe7948a209e | 46 | if(num1>255){ //pero si es mayor a 255 las cifras deben ser convertidas a un hex de dos bytes de la siguiente forma |
| kolive360 | 3:61fd3a58c5bf | 47 | j=num1/256; //calculo la cifra mas significativa |
| kolive360 | 3:61fd3a58c5bf | 48 | k=num1-j*256; //calculo la cifra menos significativa |
| Christianh | 4:ebe7948a209e | 49 | bt.putc(j); //las envio a la usart para que se las ponga al modulo bluetooth y la lleve al android |
| Christianh | 4:ebe7948a209e | 50 | bt.putc(k); //mas significativa primero, menos despues si no no funciona!!! y con la orden PUTC solo asi le envia binarios |
| Christianh | 4:ebe7948a209e | 51 | pc.printf("vol 1\n"); |
| Christianh | 4:ebe7948a209e | 52 | pc.printf("%i",num1); |
| Christianh | 4:ebe7948a209e | 53 | } |
| Christianh | 4:ebe7948a209e | 54 | |
| Christianh | 4:ebe7948a209e | 55 | if(num2<256){ //debo generar dos casos a APP inventor solo me recibe hex asi: 0xhhhh (4 cifras) |
| Christianh | 4:ebe7948a209e | 56 | bt.putc(0); //si el numero es hasta 255 se le ponen dos ceros adelante a la secuencia de bits |
| Christianh | 4:ebe7948a209e | 57 | bt.putc(num2); //luego la cifra menos significativa |
| Christianh | 4:ebe7948a209e | 58 | pc.printf("vol 1\n"); |
| Christianh | 4:ebe7948a209e | 59 | pc.printf("%i",num2); |
| Christianh | 4:ebe7948a209e | 60 | } |
| kolive360 | 3:61fd3a58c5bf | 61 | if(num2>255){ //pero si es mayor a 255 las cifras deben ser convertidas a un hex de dos bytes de la siguiente forma |
| kolive360 | 3:61fd3a58c5bf | 62 | j=num2/256; //calculo la cifra mas significativa |
| kolive360 | 3:61fd3a58c5bf | 63 | k=num2-j*256; //calculo la cifra menos significativa |
| Christianh | 4:ebe7948a209e | 64 | bt.putc(j); //las envio a la usart para que se las ponga al modulo bluetooth y la lleve al android |
| Christianh | 4:ebe7948a209e | 65 | bt.putc(k); //mas significativa primero, menos despues si no no funciona!!! y con la orden PUTC solo asi le envia binarios |
| Christianh | 4:ebe7948a209e | 66 | pc.printf("vol 1\n"); |
| Christianh | 4:ebe7948a209e | 67 | pc.printf("%i",num2); |
| Christianh | 4:ebe7948a209e | 68 | } |
| Christianh | 4:ebe7948a209e | 69 | } |
| tony63 | 1:d0a4ddc1bd88 | 70 | } |
