SPI,I2C,RTC
Dependencies: MFRC522_Updated ssd1306_library
Diff: main.cpp
- Revision:
- 10:7e62c3111814
- Parent:
- 9:935f87e2299d
- Child:
- 11:c996c388d45b
diff -r 935f87e2299d -r 7e62c3111814 main.cpp --- a/main.cpp Wed May 20 21:08:15 2020 +0000 +++ b/main.cpp Wed May 20 21:29:47 2020 +0000 @@ -1,22 +1,29 @@ #include "mbed.h" -#include "stdio.h" -#include "string.h" -#include "ssd1306.h" #include "MFRC522.h" -SSD1306 lcd (D7, D6); -Serial pc(USBTX, USBRX); -Ticker t; -int q=0; +#include "ssd1306.h" + + +DigitalOut LedRed (LED2); +DigitalOut LedGreen (LED1); +SSD1306 lcd (D7,D6); +Serial pc(USBTX, USBRX); +MFRC522 RfChip (D11, D12, D13, PTE0, D10); +Ticker tiempo1; + +int q,h; void conteo() { - q=q+1; + if(h!=0) { + q=q+1; + } } -int main() +int main(void) { - t.attach(&conteo,1); - q=1589916065; + tiempo1.attach(&conteo,1); + q=1589866116; + q=q-((5*60)*60); lcd.init(); - lcd.speed (SSD1306::Medium); + lcd.speed (SSD1306::Fast); lcd.cls(); lcd.locate (3,1); lcd.printf ("Escaner RF"); @@ -24,24 +31,62 @@ lcd.printf ("Andres Arevalo"); lcd.locate (5,1); lcd.printf ("Andres castano"); + pc.printf ("Andres castano"); lcd.redraw(); wait(3); - lcd.redraw(); + lcd.cls(); + RfChip.PCD_Init(); + h=1; while (true) { + set_time(q); + lcd.locate (1,0); + time_t seconds = time(NULL); + lcd.printf("fecha %s",ctime(&seconds)); lcd.redraw(); - set_time(q); - time_t seconds = time(NULL); - + + LedRed = 1; + LedGreen = 1; char buffer2[32]; strftime(buffer2, 32, "%m/%d/%y", localtime(&seconds)); pc.printf("%s", buffer2); char buffer1[32]; strftime(buffer1, 32, "%H:%M:%S", localtime(&seconds)); - pc.printf(" , %s\n\r", buffer1); + pc.printf(" , %s", buffer1); + pc.printf(" , sin lectura \n\r"); + + if ( ! RfChip.PICC_IsNewCardPresent()) { + wait_ms(500); + continue; + } + + LedRed = 0; + + if ( ! RfChip.PICC_ReadCardSerial()) { + wait_ms(500); + continue; + } + + + LedRed = 1; + LedGreen = 0; + + + strftime(buffer2, 32, "%m/%d/%y", localtime(&seconds)); + pc.printf("%s", buffer2); + strftime(buffer1, 32, "%H:%M:%S", localtime(&seconds)); + pc.printf(" , %s", buffer1); + pc.printf(" ,"); + lcd.locate (6,1); + for (uint8_t i = 0; i < RfChip.uid.size; i++) { + pc.printf(" %x ", RfChip.uid.uidByte[i]); + lcd.printf(" %x ", RfChip.uid.uidByte[i]); + } + pc.printf("\n\r"); + lcd.redraw(); wait(1); } }