SPI,I2C,RTC
Dependencies: MFRC522_Updated ssd1306_library
main.cpp@10:7e62c3111814, 2020-05-20 (annotated)
- Committer:
- andres0705
- Date:
- Wed May 20 21:29:47 2020 +0000
- Revision:
- 10:7e62c3111814
- Parent:
- 9:935f87e2299d
- Child:
- 11:c996c388d45b
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andres0705 | 7:6372f34c11d1 | 1 | #include "mbed.h" |
andres0705 | 9:935f87e2299d | 2 | #include "MFRC522.h" |
andres0705 | 10:7e62c3111814 | 3 | #include "ssd1306.h" |
andres0705 | 10:7e62c3111814 | 4 | |
andres0705 | 10:7e62c3111814 | 5 | |
andres0705 | 10:7e62c3111814 | 6 | DigitalOut LedRed (LED2); |
andres0705 | 10:7e62c3111814 | 7 | DigitalOut LedGreen (LED1); |
andres0705 | 10:7e62c3111814 | 8 | SSD1306 lcd (D7,D6); |
andres0705 | 10:7e62c3111814 | 9 | Serial pc(USBTX, USBRX); |
andres0705 | 10:7e62c3111814 | 10 | MFRC522 RfChip (D11, D12, D13, PTE0, D10); |
andres0705 | 10:7e62c3111814 | 11 | Ticker tiempo1; |
andres0705 | 10:7e62c3111814 | 12 | |
andres0705 | 10:7e62c3111814 | 13 | int q,h; |
20172573073 | 3:bd37bcc0ec09 | 14 | void conteo() |
20172573073 | 3:bd37bcc0ec09 | 15 | { |
andres0705 | 10:7e62c3111814 | 16 | if(h!=0) { |
andres0705 | 10:7e62c3111814 | 17 | q=q+1; |
andres0705 | 10:7e62c3111814 | 18 | } |
20172573073 | 3:bd37bcc0ec09 | 19 | } |
andres0705 | 10:7e62c3111814 | 20 | int main(void) |
20172573073 | 3:bd37bcc0ec09 | 21 | { |
andres0705 | 10:7e62c3111814 | 22 | tiempo1.attach(&conteo,1); |
andres0705 | 10:7e62c3111814 | 23 | q=1589866116; |
andres0705 | 10:7e62c3111814 | 24 | q=q-((5*60)*60); |
andres0705 | 6:820dac5cdd1e | 25 | lcd.init(); |
andres0705 | 10:7e62c3111814 | 26 | lcd.speed (SSD1306::Fast); |
20172573073 | 3:bd37bcc0ec09 | 27 | lcd.cls(); |
20172573073 | 3:bd37bcc0ec09 | 28 | lcd.locate (3,1); |
20172573073 | 5:e86f65d4cdf2 | 29 | lcd.printf ("Escaner RF"); |
20172573073 | 5:e86f65d4cdf2 | 30 | lcd.locate (4,1); |
20172573073 | 5:e86f65d4cdf2 | 31 | lcd.printf ("Andres Arevalo"); |
20172573073 | 5:e86f65d4cdf2 | 32 | lcd.locate (5,1); |
20172573073 | 5:e86f65d4cdf2 | 33 | lcd.printf ("Andres castano"); |
andres0705 | 10:7e62c3111814 | 34 | pc.printf ("Andres castano"); |
20172573073 | 4:500f1ba2d17a | 35 | lcd.redraw(); |
20172573073 | 5:e86f65d4cdf2 | 36 | wait(3); |
andres0705 | 10:7e62c3111814 | 37 | lcd.cls(); |
andres0705 | 10:7e62c3111814 | 38 | RfChip.PCD_Init(); |
andres0705 | 10:7e62c3111814 | 39 | h=1; |
andres0705 | 6:820dac5cdd1e | 40 | |
andres0705 | 6:820dac5cdd1e | 41 | while (true) { |
andres0705 | 6:820dac5cdd1e | 42 | |
andres0705 | 10:7e62c3111814 | 43 | set_time(q); |
andres0705 | 10:7e62c3111814 | 44 | lcd.locate (1,0); |
andres0705 | 10:7e62c3111814 | 45 | time_t seconds = time(NULL); |
andres0705 | 10:7e62c3111814 | 46 | lcd.printf("fecha %s",ctime(&seconds)); |
andres0705 | 6:820dac5cdd1e | 47 | lcd.redraw(); |
andres0705 | 10:7e62c3111814 | 48 | |
andres0705 | 10:7e62c3111814 | 49 | LedRed = 1; |
andres0705 | 10:7e62c3111814 | 50 | LedGreen = 1; |
20172573073 | 8:51c5c171bbf6 | 51 | char buffer2[32]; |
20172573073 | 8:51c5c171bbf6 | 52 | strftime(buffer2, 32, "%m/%d/%y", localtime(&seconds)); |
20172573073 | 8:51c5c171bbf6 | 53 | pc.printf("%s", buffer2); |
20172573073 | 8:51c5c171bbf6 | 54 | char buffer1[32]; |
20172573073 | 8:51c5c171bbf6 | 55 | strftime(buffer1, 32, "%H:%M:%S", localtime(&seconds)); |
andres0705 | 10:7e62c3111814 | 56 | pc.printf(" , %s", buffer1); |
andres0705 | 10:7e62c3111814 | 57 | pc.printf(" , sin lectura \n\r"); |
andres0705 | 10:7e62c3111814 | 58 | |
andres0705 | 10:7e62c3111814 | 59 | if ( ! RfChip.PICC_IsNewCardPresent()) { |
andres0705 | 10:7e62c3111814 | 60 | wait_ms(500); |
andres0705 | 10:7e62c3111814 | 61 | continue; |
andres0705 | 10:7e62c3111814 | 62 | } |
andres0705 | 10:7e62c3111814 | 63 | |
andres0705 | 10:7e62c3111814 | 64 | LedRed = 0; |
andres0705 | 10:7e62c3111814 | 65 | |
andres0705 | 10:7e62c3111814 | 66 | if ( ! RfChip.PICC_ReadCardSerial()) { |
andres0705 | 10:7e62c3111814 | 67 | wait_ms(500); |
andres0705 | 10:7e62c3111814 | 68 | continue; |
andres0705 | 10:7e62c3111814 | 69 | } |
andres0705 | 10:7e62c3111814 | 70 | |
andres0705 | 10:7e62c3111814 | 71 | |
andres0705 | 10:7e62c3111814 | 72 | LedRed = 1; |
andres0705 | 10:7e62c3111814 | 73 | LedGreen = 0; |
20172573073 | 8:51c5c171bbf6 | 74 | |
andres0705 | 10:7e62c3111814 | 75 | |
andres0705 | 10:7e62c3111814 | 76 | |
andres0705 | 10:7e62c3111814 | 77 | strftime(buffer2, 32, "%m/%d/%y", localtime(&seconds)); |
andres0705 | 10:7e62c3111814 | 78 | pc.printf("%s", buffer2); |
andres0705 | 10:7e62c3111814 | 79 | strftime(buffer1, 32, "%H:%M:%S", localtime(&seconds)); |
andres0705 | 10:7e62c3111814 | 80 | pc.printf(" , %s", buffer1); |
andres0705 | 10:7e62c3111814 | 81 | pc.printf(" ,"); |
andres0705 | 10:7e62c3111814 | 82 | lcd.locate (6,1); |
andres0705 | 10:7e62c3111814 | 83 | for (uint8_t i = 0; i < RfChip.uid.size; i++) { |
andres0705 | 10:7e62c3111814 | 84 | pc.printf(" %x ", RfChip.uid.uidByte[i]); |
andres0705 | 10:7e62c3111814 | 85 | lcd.printf(" %x ", RfChip.uid.uidByte[i]); |
20172573073 | 3:bd37bcc0ec09 | 86 | |
andres0705 | 10:7e62c3111814 | 87 | } |
andres0705 | 10:7e62c3111814 | 88 | pc.printf("\n\r"); |
andres0705 | 10:7e62c3111814 | 89 | lcd.redraw(); |
20172573073 | 0:fbda9e7e9269 | 90 | wait(1); |
20172573073 | 0:fbda9e7e9269 | 91 | } |
20172573073 | 8:51c5c171bbf6 | 92 | } |