.
Dependencies: mbed Servo MFRC522_Updated HC-SR04 ssd1306_library
Diff: main.cpp
- Revision:
- 1:849d12c9b2be
- Parent:
- 0:366b3e64c83c
- Child:
- 2:ad8f0cdf7015
--- a/main.cpp Sat Jun 06 21:46:44 2020 +0000 +++ b/main.cpp Tue Jun 09 05:15:28 2020 +0000 @@ -4,16 +4,21 @@ #include "HCSR04.h" #include "MFRC522.h" #include "ssd1306.h" + +MFRC522 RfChip (D11, D12, D13, PTE0, D10); SSD1306 lcd (D7,D6); BusOut display7Seg(PTC10, PTC7, PTC6, PTC4, PTC0, PTB19, PTB18); DigitalOut display1(PTC11); DigitalOut display2(PTC13); +DigitalOut display3(PTC16); Servo myservo(D2); -Thread thread; + Thread t; Thread t1; Thread t2; Thread t3; +Thread t4; + Serial pc(USBTX, USBRX); HCSR04 sonar(D3,D4); int a,q; @@ -37,56 +42,70 @@ void servo() { + while(true) { menor = sonar.getCm(); - a=0; for(int i=0; i<40; i++) { myservo = i/40.0; da = sonar.getCm(); - pc.printf("Distancia %.2f cm \n\r",da); + pc.printf("%1.f , %.2f \n\r",float(i*4.5),da); if(menor > da) { menor = da; a=(i*180)/40; } //ThisThread::sleep_for(500); - wait(0.5); + wait(0.05); } - pc.printf("menor final %.2f cm \n\r",menor); menor=sonar.getCm(); a=0; for(int i=40; i>0; i--) { myservo = i/40.0; da = sonar.getCm(); - pc.printf("Distancia %.2f cm \n\r",da); + pc.printf("%1.f , %.2f \n\r",float(i*4.5),da); if(menor > da) { menor = da; a=(i*180)/40; } //ThisThread::sleep_for(500); - wait(0.5); + wait(0.05); } - pc.printf("menor %.2f cm \n\r",menor); } } void seg7() { while(1) { - int d,u,n; + int d,u,n,c; n=int(menor); - - d = n /10; + + c= n/100; + d = (n - (c*100))/10; u = n % 10; display1=1; display2=0; + display3=0; display7Seg=anodeComun[d]; + //ThisThread::sleep_for(25); - wait(0.025); + wait(0.003); + display1=0; display2=1; + display3=0; display7Seg=anodeComun[u]; + //ThisThread::sleep_for(25); - wait(0.025); + wait(0.003); + + display1=0; + display2=0; + display3=1; + display7Seg=anodeComun[c]; + + //ThisThread::sleep_for(25); + wait(0.003); + + } } void oled() @@ -95,35 +114,54 @@ lcd.init(); lcd.speed (SSD1306::Fast); lcd.cls(); - lcd.locate (3,1); - lcd.printf ("angulo :%d ",a); + lcd.locate (4,1); + lcd.printf ("dis menor :%2.f ",menor); lcd.locate (5,1); - lcd.printf ("dis menor :%2.f ",menor); - set_time(q); + lcd.printf ("angulo :%d ",a); lcd.locate (1,0); time_t seconds = time(NULL); - lcd.printf("fecha %s",ctime(&seconds)); + lcd.printf("Fecha= %s", ctime(&seconds)); lcd.redraw(); + //ThisThread::sleep_for(500); wait(0.5); } } -void tiempo() +void rf() { while(1) { - q=q+1; + lcd.init(); + lcd.speed (SSD1306::Fast); + if ( ! RfChip.PICC_IsNewCardPresent()) { + //ThisThread::sleep_for(500); + wait_ms(500); + continue; + } + if ( ! RfChip.PICC_ReadCardSerial()) { + //ThisThread::sleep_for(500); + wait_ms(500); + continue; + } + uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); + lcd.locate (6,3); + lcd.printf(" %s ", RfChip.PICC_GetTypeName(piccType)); + lcd.redraw(); //ThisThread::sleep_for(1000); - wait(1); + wait_ms(1000); } } + + int main() { myservo.calibrate(0.0015,360); + set_time(1591673863); + RfChip.PCD_Init(); t.start((servo)); + t.set_priority (osPriorityNormal3); t1.start(seg7); + t1.set_priority (osPriorityNormal2); t2.start(oled); - t3.start(tiempo); - q=1590029272; - q=q-((5*60)*60); - //thread.flags_set(STOP_FLAG); - //thread.join(); + t2.set_priority (osPriorityNormal1); + t4.start(rf); + t.join(); } \ No newline at end of file