Cambios
Dependencies: mbed Adafruit_GFX SeeedShieldBot BluetoothSerial
Diff: main.cpp
- Revision:
- 3:b33d698b0a5c
- Parent:
- 2:8e21f1f358bc
- Child:
- 4:5182de07691c
diff -r 8e21f1f358bc -r b33d698b0a5c main.cpp --- a/main.cpp Mon Dec 21 12:39:42 2020 +0000 +++ b/main.cpp Mon Dec 21 16:26:20 2020 +0000 @@ -1,13 +1,6 @@ #include "mbed.h" #include "hcsr04.h" #include "Adafruit_SSD1306.h" -/*#include "estadomovder.h" -#include "estadoinicio.h" -#include "estadocalentar.h" -#include "estadomovizq1.h" -#include "estadocentro.h" -#include "estadomovizq2.h" -#include "estadosoplado.h"*/ class I2CPreInit : public I2C @@ -21,10 +14,10 @@ }; I2CPreInit gI2C(PB_9,PB_8); +Adafruit_SSD1306_I2c gOled(gI2C,NC,0x78,64,128); Serial pc(USBTX, USBRX); // tx, rx Serial bt(A5, A4); // tx, rx -Adafruit_SSD1306_I2c gOled(gI2C,NC,0x78,64,128); Ticker repeticion; DigitalOut led(LED1); @@ -50,7 +43,6 @@ float corriente=((Aout.read()*5)-2.5)/0.185; - pc.printf("Intensidad medida = %.4f A \n", corriente); bt.printf("Intensidad medida = %.4f A \n", corriente); } @@ -68,10 +60,11 @@ estado = movder; gOled.printf("Fabricando\n"); - bt.printf("Transportando\n"); + bt.printf("Transportando a calentador\n"); - } else { //Si el dato es cualquier otra cosa no empieza a hacer nada + } else { + bt.printf("Reposo\n"); //Si el dato es cualquier otra cosa no empieza a hacer nada } } } @@ -90,8 +83,7 @@ } else { enable=0; estado=calentar; - //gOled.clearDisplay(); - //gOled.printf("Calentando\n"); + bt.printf("Calentando\n"); } @@ -99,25 +91,23 @@ void estadocalentar() { - rele=1; float tension=Vout.read()*3.3; //pc.printf("Valor voltios %.4f leido flat\n",tension); float resistencia= ((3.3*100000.0)/tension)-100000.0; - float temp= 3950.0/(log(resistencia/100000.0)+(3950.0/298.0)); + float temp= (3950.0/(log(resistencia/100000.0)+(3950.0/298.0))-273.0); bt.printf("Calentando a: %.4f\n",temp); - //gOled.printf("Calentando a: %.4f\n",temp); + - if (temp<308.0) { - //rele.write(1); + if (temp<35.0) { + rele=1; } else { rele=0; estado=movizq1; - //gOled.clearDisplay(); - //gOled.printf("Transportando\n"); - bt.printf("Transportando\n"); + + bt.printf("Transportando a revision\n"); } } @@ -139,9 +129,8 @@ } else { enable=0; estado=centro; - //gOled.clearDisplay(); - //gOled.printf("Comprobar\n"); - bt.printf("Centro\n"); + + bt.printf("Revisando\n"); } } @@ -156,15 +145,17 @@ if (dato=='2') { //Si el dato es un 1 comienza el proceso estado = movder; - //gOled.printf("Pieza incorrecta\n"); + bt.printf("Pieza incorrecta\n"); + bt.printf("Transportando a calentador\n"); } else if(dato=='3') { //Si el dato es una b enciende el led estado = movizq2; - //gOled.printf("Pieza correcta\n"); + bt.printf("Pieza correcta\n"); + bt.printf("Transportando a soplador\n"); } } } @@ -181,8 +172,7 @@ } else { enable=0; estado=soplado; - //gOled.clearDisplay(); - //gOled.printf("Soplando\n"); + bt.printf("Soplando\n"); } } @@ -191,11 +181,11 @@ { dirAMotor=0; dirBMotor=1; - wait(5); + wait(7); dirAMotor=0; dirBMotor=0; estado=inicio; - gOled.clearDisplay(); + gOled.printf("Reposo\n"); bt.printf("Reposo\n"); @@ -209,11 +199,8 @@ pc.baud(115200); estado = inicio; gOled.begin(); - gOled.clearDisplay(); - gOled.printf("Reposo\n"); - bt.printf("Reposo\n"); - repeticion.attach(&medir_corriente, 5.0); //Medir la intensidad cada tres segundos + repeticion.attach(&medir_corriente, 10.0); //Medir la intensidad cada tres segundos while(1) {