Cambia intensidad de color del led, recibe valores de los sliders aplicación de app inventor

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
PROCESADORES_2017_2
Date:
Tue Nov 28 19:52:24 2017 +0000
Commit message:
Cambia intensidad de color del led, recibe valores de los sliders aplicaci?n de app inventor.

Changed in this revision

mbed.bld Show annotated file Show diff for this revision Revisions of this file
slider.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 28 19:52:24 2017 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/slider.cpp	Tue Nov 28 19:52:24 2017 +0000
@@ -0,0 +1,113 @@
+ 
+#include "mbed.h"
+ 
+ 
+Serial pc(USBTX, USBRX); //Configurar salida serial para PC;
+Serial BT(PTE22,PTE23);  //RX-TX  puertos del FRDM para el modem bluetooth;
+PwmOut PWM1(PTB1); //Configuro una salida PWM; 
+PwmOut ledR(LED1);
+PwmOut ledV(LED2);
+PwmOut ledA(LED3);
+ 
+ 
+ 
+int main()
+{
+    ledR=ledV=ledA=1;
+    BT.baud(9600);   // asigno baudios y configuro puerto serie de la usart
+    BT.format(8,Serial::None,1); //8bits - No parity bit - one stop bit
+    //int nu ;
+    int val;
+    
+    char c ; //Variable para leer desde el BT
+ 
+    
+    
+    //int comando=0; //Variable que usaré para saber qué parámetro está siendo enviado;
+    pc.printf("Slider y led RGB: \n\r   Procesadores 2017\n\r ");
+    
+    while (1) 
+    { //Loop...
+        
+       
+            
+            //Leer información del bluetooth
+       if (BT.readable())
+       {    
+            
+            c = BT.getc(); //Leo el valor del bluetooth;
+            //LED ROJO---------------------------------------------------------
+            
+            //el primer slider entrega valores entre 0-100
+            
+            if ((c>0) && (c<=100)){
+            
+            val= (int)(c);
+                        
+            float p1= float(val);
+            float p2=p1/100;
+            if (p2<0.2){
+                p2=0;
+                }
+            ledR=(1-p2);
+            
+            //pc.printf("val p %.2f\n", p2);
+            //wait(0.2);
+                
+            }
+            
+            //LED VERDE
+            
+            //el segundo slider entrega valores entre 100-200
+            if ((c>100) && (c<=200)){
+                     
+             val= (int)(c);
+             val=val-100;   //para que quede valor entre 0-100
+            
+            float p1= float(val);  //el entero v se convierte en flotante para dividir
+            
+            float p2=p1/100;
+            if (p2<0.2){   //apaga en valores cercanos a 0
+                p2=0;
+                }
+            ledV=(1-p2);  //el pwm se enciende entre 0-1
+            
+            //pc.printf("val p %.2f\n", p2);
+            //wait(0.2);
+                
+            }
+            
+            //LED AZUL
+               if ((c>200) && (c<=300)){
+                 
+                if(c>255){
+                    ledA=0;    
+                    ledR=1;
+                    ledV=1;
+                        }
+                                               
+                        else {
+                        
+                        val= (int)(c);
+                        val=val-200;
+                                              
+                        //pc.printf("numero %i\n", v);
+                        float p1= float(val);
+                        
+                        float p3=p1/100;  //lleva a rango [0-1]
+                        if (p3<0.2){      //en valores pequeños apaga
+                            p3=0;
+                            }
+                        ledA=(1-p3);
+                        ledR=1;
+                        ledV=1;
+                        //pc.printf("val p %.2f\n", p2);
+                        //wait(0.2);
+                        } 
+            } 
+        }
+    }
+}
+ 
+            
+ 
\ No newline at end of file