SPI,I2C,RTC

Dependencies:   MFRC522_Updated ssd1306_library

main.cpp

Committer:
andres0705
Date:
2020-05-20
Revision:
10:7e62c3111814
Parent:
9:935f87e2299d
Child:
11:c996c388d45b

File content as of revision 10:7e62c3111814:

#include "mbed.h"
#include "MFRC522.h"
#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()
{
    if(h!=0) {
        q=q+1;
    }
}
int main(void)
{
    tiempo1.attach(&conteo,1);
    q=1589866116;
    q=q-((5*60)*60);
    lcd.init();
    lcd.speed (SSD1306::Fast);
    lcd.cls();
    lcd.locate (3,1);
    lcd.printf ("Escaner RF");
    lcd.locate (4,1);
    lcd.printf ("Andres Arevalo");
    lcd.locate (5,1);
    lcd.printf ("Andres castano");
    pc.printf ("Andres castano");
    lcd.redraw();
    wait(3);
    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();
        
        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", 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);
    }
}