Este programa se usa en recepcion de cadenas de caracteres, util para probar programas de conexion bluetooth en APPINVENTOR

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
tony63
Date:
Sat Jun 08 04:11:51 2019 +0000
Parent:
1:bf58c37db6af
Commit message:
programa ejemplo para pasar salidas de caracter en valores flotantes y digitales

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r bf58c37db6af -r 7dcf65d8c0d1 main.cpp
--- a/main.cpp	Fri Mar 31 04:25:45 2017 +0000
+++ b/main.cpp	Sat Jun 08 04:11:51 2019 +0000
@@ -3,10 +3,12 @@
 #include "mbed.h"
 #include "stdio.h"
 #include "string.h"
+#include "stdlib.h"
+
  
 Serial GSM(PTE0,PTE1);  //puertos del FRDM para el modem
 Serial pc(USBTX,USBRX); //puertos del PC
-char buffer[20];// TAMAÑO DEL BUFER
+char buffer[5];// TAMAÑO DEL BUFER
 Timer t;   //VALOR DEL TIEMPO
 int count;
 int i = 0;
@@ -15,8 +17,13 @@
 char Qr[]="qmAIzQGtSK";
 DigitalOut LedRojo(LED1);
 DigitalOut LedVerde(LED2);
+char s2[4];
+char s1[4];
 DigitalOut LedAzul(LED3);
- 
+PwmOut led(PTA13);
+AnalogOut aout(PTE30);
+char *cadena = "";
+float pm; 
 int readBuffer(char *buffer,int count)   //esta funcion lee un bufer de datos
 {
     int i=0; 
@@ -55,11 +62,13 @@
        wait(2);   //PRENDE EL LED VERDE POR 2 SEGUNDOS
        LedVerde=1;
        GSM.baud(9600);
-       GSM.format(8,Serial::None,1); 
+       GSM.format(8,Serial::None,1);
+       led.period(0.005f);      // 4 second period
+       led.write(0.40f);      // 50% duty cycle, relative to period 
                
        while(1){ 
        if (GSM.readable()) {
-          readBuffer(buffer,10);
+          readBuffer(buffer,5);
           pc.printf("buffer= %s\n\r ",buffer);  //imprime el bufer
           pc.printf("buffer= %c  %c\n\r ",buffer[0],buffer[1]);//imprime el cero y el uno
           
@@ -71,10 +80,44 @@
           
           if(buffer[0]=='O' && buffer[1]=='N' && buffer[2]=='R' ){LedRojo=0;}  //PRENDE EL LED ROJO
           if(buffer[0]=='O' && buffer[1]=='F'&& buffer[2]=='R'){LedRojo=1;}  //APAGA EL LED ROJO
-          
-          
-          
+          char *s2 = buffer;
+          strcpy( s1, s2 );
+          int num = atoi(s1);
+          pm=num/100.0;
+          led.write(pm);
+          aout=pm;
+          pc.printf("num= %d\n\r ",num);  //imprime el bufer
+          pc.printf("pm= %f\n\r ",pm);  //imprime el bufer 
+          cleanBuffer(buffer,5);   
           } 
-          cleanBuffer(buffer,10);           
+          cleanBuffer(buffer,5);           
+}
 }
-}
\ No newline at end of file
+
+/*
+char *cadena = "4856"; 
+int num = atoi(cadena);
+
+PwmOut led(PTA13);
+DigitalOut myled(LED2);
+
+int main() {
+led.period(0.005f);  // 4 second period
+led.write(0.40f);   
+
+
+PwmOut led(LED1);
+ 
+int main() {
+    // specify period first
+    led.period(4.0f);      // 4 second period
+    led.write(0.50f);      // 50% duty cycle, relative to period
+    
+     stdlib.h
+     char *str = "12345.67"; 
+
+n = atoi(str); 
+printf("string = %s integer = %d\n", str, n); 
+ strcpy( s1, s2 );
+    
+*/
\ No newline at end of file