wss
Dependencies: mbed Adafruit_GFX DS1820
Diff: main.cpp
- Revision:
- 15:2acad1c57ad4
- Parent:
- 14:21cb6b2ac16b
--- a/main.cpp Tue Dec 14 13:05:02 2021 +0000 +++ b/main.cpp Tue Dec 14 14:59:26 2021 +0000 @@ -33,6 +33,7 @@ HCSR04 usensor(D7,D8); //(PinName TrigPin,PinName EchoPin): DigitalIn finalDer(D2); DigitalIn finalIzq(D3); +DigitalIn boton(D5); DigitalOut step(D13); DigitalOut dir(D12); DigitalOut enable(D11); @@ -45,8 +46,8 @@ int contador=0; -char x='0'; -char y='0'; +int x=0; +int y=0; //if (x==1){ //y=0; // }else{ @@ -76,7 +77,8 @@ void estadoCerrada() { - if (x=='1') { + + if (x==1) { if( (finalIzq == 1) && contador <3) { wait(0.5); enable=1; @@ -87,16 +89,16 @@ //distancia < 5 } else if(contador==3) { - y='1'; - x='0'; + x=0; + contador=0; } } - if(x=='0' &&y=='0') { + if(x==0 &&y==0) { pc.printf("No seleccionado programa\r\n"); } - if(y=='1') { + if(y==1) { if(finalIzq == 1 && finalDer==1) { enable=1; @@ -112,7 +114,7 @@ void estadoAbriendose() { - if(x=='1') { + if(x==1) { //pc.printf("Distance =%d\n",distancia); if((finalDer==1)) { @@ -131,7 +133,7 @@ //estado=cerrandose; // } - if(y=='1') { + if(y==1) { if(tiempo.read()<0.5) { @@ -150,7 +152,7 @@ void estadoCerrandose() { //pc.printf("Distance =%d\n",distancia); - if(x=='1') { + if(x==1) { if((finalIzq==1)) { estado=cerrada; @@ -183,7 +185,7 @@ gOled.printf("temp = %3.1f C\r\n", temp); gOled.display(); gOled.setTextCursor(0,0); - + pc.printf("temp = %3.1f C\r\n", temp); } @@ -199,6 +201,12 @@ gOled.display(); //x=(pc.getc()); //pc.printf("Estado cerrada\n"); + + if (boton ==1){ + x=1; + } + + if(x==1) { gOled.clearDisplay(); gOled.printf("Programa de transporte de piezas\n"); @@ -212,40 +220,47 @@ } tiempo.reset(); - int error = 0; + //int error = 0; pc.baud(115200); - if(ds1820.begin()) { - while(1) { + //if(ds1820.begin()) { + //while(1) { - ds1820.startConversion(); // start temperature conversion from analog to digital - wait(1.0); // let DS1820 complete the temperature conversion - error = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) - switch(error) { - case 0: // no errors -> 'temp' contains the value of measured temperature - pc.printf("temp = %3.1f C\r\n", temp); - break; - case 1: // no sensor present -> 'temp' is not updated - pc.printf("no sensor present\n\r"); - break; - case 2: // CRC error -> 'temp' is not updated - pc.printf("CRC error\r\n"); - } - led = !led; - } - } else - pc.printf("No DS1820 sensor found!\r\n"); + // ds1820.startConversion(); // start temperature conversion from analog to digital + // wait(1.0); // let DS1820 complete the temperature conversion + // error = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) + // switch(error) { + // case 0: // no errors -> 'temp' contains the value of measured temperature + // pc.printf("temp = %3.1f C\r\n", temp); + // break; + // case 1: // no sensor present -> 'temp' is not updated + // pc.printf("no sensor present\n\r"); + // break; + // case 2: // CRC error -> 'temp' is not updated + // pc.printf("CRC error\r\n"); + // } + // led = !led; + // } + // } else + // pc.printf("No DS1820 sensor found!\r\n"); - +//if(x==1 || y==1){ while(1) { + distancia=usensor.get_dist_cm(); if(pc.readable()) { x=(pc.getc()); } + + if (boton ==1){ + x=1; + led=1; + } + //calefactor // rele=1; // led=1; @@ -254,9 +269,24 @@ // led=0; // wait(1.0); // - if(pc.readable()) { - x=(pc.getc()); - } + // if(ds1820.begin()) { + // ds1820.startConversion(); // start temperature conversion from analog to digital + // wait(1.0); // let DS1820 complete the temperature conversion + // error = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) + // switch(error) { + // case 0: // no errors -> 'temp' contains the value of measured temperature + // pc.printf("temp = %3.1f C\r\n", temp); + // break; + // case 1: // no sensor present -> 'temp' is not updated + // pc.printf("no sensor present\n\r"); + // break; + // case 2: // CRC error -> 'temp' is not updated + // pc.printf("CRC error\r\n"); + // } + // led = !led; + // } + // else + // pc.printf("No DS1820 sensor found!\r\n"); switch ( estado ) { case cerrada: @@ -274,5 +304,8 @@ default: break; } + + } -} + } +//}