proyrcto

Dependencies:   Adafruit_GFX mbed

Files at this revision

API Documentation at this revision

Comitter:
juankafil1
Date:
Tue Dec 05 11:16:14 2017 +0000
Commit message:
transversal

Changed in this revision

Adafruit_GFX.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Adafruit_GFX.lib	Tue Dec 05 11:16:14 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/JojoS/code/Adafruit_GFX/#0b35bb153799
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 05 11:16:14 2017 +0000
@@ -0,0 +1,380 @@
+ #include "mbed.h"
+// #include "SSD1306.h"
+#include "Adafruit_SSD1306.h"
+#define SDA                  PTE0
+#define SCL                  PTE1
+DigitalIn boton(PTB0);
+DigitalIn boton1(PTB1);
+DigitalOut led(LED1);
+DigitalOut led1(LED3);
+DigitalOut p(PTC16);
+Timer x;
+
+Serial rs232(USBTX, USBRX);
+BusOut step_secuence(PTD6, PTA17,  PTA16,  PTC17);
+unsigned int num_pasos,i,g=0,k,aux=0,color=1,n1=0,v1=0,a1=0,d1=0;
+int grados,b=0,c=0,tiempo=0,a=0;
+Timer t;
+ class I2C2 : public I2C 
+{
+public:
+    I2C2(PinName sda, PinName scl) : I2C(sda, scl) {
+        frequency(400000);
+        start();
+    };
+};
+
+I2C2 gI2C(SDA,SCL);
+Adafruit_SSD1306_I2c gOled2(gI2C, NC, 0x78, 64, 128);
+
+
+void retro(int cont_pasos)   // Retroceso motor
+{
+    k=0;
+    for (i = 0; i<=cont_pasos; i++) {
+        if (k>=4) {
+            k=0;
+        }
+        switch (k) {
+            case 0:
+                step_secuence=0x06;
+                break;
+            case 1:
+                step_secuence=0x05;
+          break;
+            case 2:
+                step_secuence=0x09;
+                break;
+            case 3:
+                step_secuence=0x0A;
+                break;
+             
+        }
+        wait(0.2);
+        ++k;
+    }
+}
+void forward(int cont_pasos) // Avance motor
+{
+    k=0;
+    for (i = 0; i<=cont_pasos; i++) {
+        if (k>=4) {
+            k=0;
+        }
+        switch (k) {
+            case 0:
+                step_secuence=0x0A;
+                break;
+            case 1:
+                step_secuence=0x09;
+
+                break;
+                
+            case 2:
+                step_secuence=0x05;
+                break;
+            case 3:
+                step_secuence=0x06;
+                  
+                break;
+        }
+        ++k;
+        wait(0.2);
+    }
+   
+}
+
+ 
+ Timer Timer1;
+ InterruptIn int1(PTD0);
+ 
+unsigned int  contador=0,frec=0,conn=0,conm=0,cona=0, conN=0;
+uint16_t V = 0, N = 0, A = 0, R = 0;
+
+
+void ISR_PTD0(){//cuenta los  pulsos
+    ++contador;}
+    
+void frecuencia(){
+    
+    contador=0;
+    Timer1.start();//arranca  temporizador 
+    while(Timer1.read_ms()<=10);//cuando lleve  a  10 ms pare
+    Timer1.stop();//lo detengo 
+    frec=100*contador;//lo multiplicamos  por 100
+    Timer1.reset();}//reinicia  el timer 
+    
+ void  contadores(){
+    if((frec>=1)&&(frec<=2000)){
+       gOled2.setTextCursor(0, 16);
+            gOled2.printf("esperando"); }
+    else if((frec>=2100)&&(frec<=5900)){
+        n1=1;
+        color=2;
+            rs232.printf("%d",4);
+            gOled2.clearDisplay();
+            gOled2.setTextCursor(0, 16);
+            gOled2.printf("Detectado color Negro\n");
+            conn=conn+1;//aumento  el  contador 
+            N=conn;     
+            gOled2.printf("Numero de cajas:\n%u",N);       
+            //lcd.locate(0,1);//preparado para  pubicar
+          //  wait(2);//retraso mientras  pasa  la caja 
+        
+             }
+    else if((frec>=6000)&&(frec<=12900)){
+        v1=1;
+        color=3;
+        rs232.printf("%d",3);
+            gOled2.clearDisplay();
+            gOled2.setTextCursor(0, 16);
+            gOled2.printf("Detectado color\n");//publico  el color de la  frecuencia
+            gOled2.printf("Violeta\n");
+            conm=conm+1;//aumento  el  contador 
+            V=conm;
+            gOled2.printf("Numero de cajas:\n%u",V);
+           // rs232.printf("violeta\n\r%d",conm);
+    //        wait(2);//retraso mientras  pasa  la caja   
+          
+    }else if((frec>=13000)&&(frec<=24000)){
+a1=1;
+color=4;
+            rs232.printf("%d",2);
+            gOled2.clearDisplay();
+            gOled2.setTextCursor(0, 16);
+            gOled2.printf("Detectado color Azul\n");
+            cona=cona+1;//aumento  el  contador 
+            A=cona; 
+            gOled2.printf("Numero de cajas:\n%u",A);
+      //      wait(2);
+      }    // rs232.printf("azul\n\r%d",cona);}
+            
+     else { 
+    color=1;
+    d1=1;
+        uint16_t R = 0;
+        rs232.printf("%d",1);
+        gOled2.clearDisplay();
+        gOled2.setTextCursor(0, 16);
+        gOled2.printf("Caja no reconocida\n");
+        conN=conN+1;
+        R=conN; 
+        gOled2.printf("Numero de cajas:\n%u",R);
+        //wait(2);
+       
+            
+          }     
+    }
+        
+    void motor() {
+        
+               
+   if(color==1){
+      if(n1==1){
+          forward(12);
+          grados=90;
+          //k=10000;
+           n1=0; 
+             }
+        else if(v1==1){
+          forward(24);
+           grados=180;
+          v1=0;    
+              }
+     else if(a1==1){        
+          retro(12);
+           grados=90;
+           wait(2);
+          a1=0;    
+       } else {
+        
+        wait(2);  
+             }       
+             
+  }if(color==2){
+       if(d1==1){
+         //while(1){
+          retro(12);
+           grados=90;
+           wait(2);
+           d1=0;
+           tiempo=2150;
+           
+          wait(2);
+          //aux=aux+1;//variable para el  while   
+             }
+              //aux=0; }
+        else if(v1==1){
+           forward(12);
+            grados=90;
+            wait(2);
+          v1=0;
+              }
+     else if(a1==1){ 
+          retro(24);
+         grados=180;
+      a1=0;     
+        } else {
+        wait(2); 
+             }       
+             
+  }if(color==3){
+      if(d1==1){
+          forward(24);
+           grados=180;
+           d1=0;
+           tiempo=3250;
+    }
+            
+        else if(n1==1){    
+          retro(12);
+           grados=90;
+           wait(2);
+          n1=0;//ponemos la posicion anterior en 0
+        }
+     else if(a1==1){
+         forward(12);
+          grados=90;
+          wait(2);
+          a1=0;//ponemos la posicion anterior en 0      
+       } else {
+        wait(2);
+             }       
+             
+  }if(color==4){
+      if(d1==1){
+          forward(12);
+           grados=90;
+           wait(2);
+           d1=0;
+           }
+        else if(v1==1){
+           retro(12);
+            grados=90;
+            wait(2);
+          v1=0;             
+              }
+     else if(n1==1){
+          retro(24);
+           grados=180;
+          n1=0;
+                   } else {
+        wait(2);  
+             }       
+             
+  }
+  }
+  
+    void receivedByte(){
+     int a23=0,a2=1;
+     int dato_in=rs232.getc();
+     if(dato_in=='N'){
+         p=1;
+         frec=2400;
+         }
+     if(dato_in=='A'){
+         p=1;
+        frec= 18000;}
+      if(dato_in=='V'){
+          p=1;
+         frec=8000;}
+     if(dato_in=='D'){
+         frec=32000;
+          p=1;}
+        contadores();
+        motor();
+        if(p==1){
+         while(a23<=110){
+             if(boton1==0){
+                wait(1.5);
+                p=0;
+                a2=0;
+                rs232.printf("%d",6);
+                break;
+                }a23++;
+                wait(0.1);}}
+         if(a2==0){
+             rs232.printf("%d",5);}}
+        
+int main(){//clase  principal
+d1=1;
+
+    gOled2.clearDisplay();
+    gOled2.display();
+    gOled2.setTextCursor(10, 24);
+    gOled2.printf("Iniciando presenta-cion transversal...\n\r");
+    gOled2.printf("          :v");
+    wait(5);
+ 
+     while(1){
+               rs232.attach(&receivedByte);
+              if(boton==0){
+                rs232.printf("%d",0);
+                t.start();
+                while(t.read_ms()<=2000);
+                t.stop();
+                b=b+1;
+          led=0;
+          p=1;
+         led1=1;
+        //  rs232.printf("conteo= %d \n\r", b);
+           t.reset();
+            
+                t.start();
+               while(t.read_ms()<=4500);
+               t.stop();
+         rs232.baud(9600);
+         int1.mode(PullUp);//habilitamos resistencia de PullUp
+         int1.rise(&ISR_PTD0);//si hay  flanco  de  subida se va a el programa, habilita la interrupcion  
+        //gOled2.printf("Iniciando presentacion transversal...\n"); //mensaje inicial al encender la Oled
+         gOled2.display();
+        
+         t.reset();
+         p=0;
+         frecuencia();
+        
+         t.start();
+               while(t.read_ms()<=2000);
+               t.stop();
+         p=1;
+         t.reset();
+        contadores();
+         motor ();
+        //inicia  el sub programa  frecuenia
+       //inicia el programa de los contadores y publicacion de la frecuencia
+      //  rs232.printf("%dF=%d\n\r",frec,tiempo);
+       
+        //gOled2.clearDisplay();
+    gOled2.display();
+    gOled2.setTextCursor(0, 0);
+    gOled2.printf("se movio%d\n",grados);
+    
+           while(a<=50){
+            if(boton1==0){
+                wait(1.5);
+                p=0;
+                c=c+1;
+                rs232.printf("%d",6);
+                break;
+                }a++;
+                wait(0.1);}
+                a=0;
+            if(b!=c){
+                p=0;
+                rs232.printf("%d",5);
+                }
+            
+             
+             
+             
+            
+                
+              
+        
+        }else
+         gOled2.display();
+    gOled2.setTextCursor(0, 0);
+    gOled2.printf("esperando..");
+        }
+        }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Dec 05 11:16:14 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600
\ No newline at end of file