Sippakorn Saeng-aroon
/
InventorStudio_LCP2
v1.1
main.cpp@4:4b28e4aa1742, 2019-05-05 (annotated)
- Committer:
- sippasaeng
- Date:
- Sun May 05 18:17:07 2019 +0000
- Revision:
- 4:4b28e4aa1742
- Parent:
- 3:054df6da48b5
v1.1 update char-->int type
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pokpongc | 0:ef2ee7458c37 | 1 | #include "mbed.h" |
pokpongc | 0:ef2ee7458c37 | 2 | #include "QEI.h" |
sippasaeng | 4:4b28e4aa1742 | 3 | #include "MFRC522.h" |
sippasaeng | 4:4b28e4aa1742 | 4 | |
sippasaeng | 4:4b28e4aa1742 | 5 | #define MF_RESET D8 |
pokpongc | 0:ef2ee7458c37 | 6 | |
pokpongc | 0:ef2ee7458c37 | 7 | Serial pc(USBTX, USBRX); |
pokpongc | 0:ef2ee7458c37 | 8 | |
sippasaeng | 4:4b28e4aa1742 | 9 | MFRC522 RfChip (D11, D12, D13, D10, D8); |
sippasaeng | 4:4b28e4aa1742 | 10 | |
sippasaeng | 4:4b28e4aa1742 | 11 | QEI temp_dial(A3, A4, A1, 50, QEI::X4_ENCODING); |
pokpongc | 0:ef2ee7458c37 | 12 | BusIn joy_bus{D3, D4, D5, D6}; |
pokpongc | 0:ef2ee7458c37 | 13 | BusIn button_bus{D7, D9}; |
pokpongc | 1:8e3af9643155 | 14 | DigitalIn a(D7),b(D9),c(D3),d(D4),e(D5),f(D6); //Dummy pin for pulling |
pokpongc | 0:ef2ee7458c37 | 15 | |
sippasaeng | 4:4b28e4aa1742 | 16 | |
sippasaeng | 4:4b28e4aa1742 | 17 | int data[8],RFID_Tag = 0; |
sippasaeng | 4:4b28e4aa1742 | 18 | unsigned int sum_x = 0; |
pokpongc | 0:ef2ee7458c37 | 19 | |
pokpongc | 1:8e3af9643155 | 20 | void init_(); |
sippasaeng | 4:4b28e4aa1742 | 21 | void RFID_Tag_Read(); |
pokpongc | 1:8e3af9643155 | 22 | |
pokpongc | 0:ef2ee7458c37 | 23 | int main() { |
sippasaeng | 4:4b28e4aa1742 | 24 | |
sippasaeng | 4:4b28e4aa1742 | 25 | |
pokpongc | 2:eb82f5cb5098 | 26 | uint16_t pulse = 0; |
pokpongc | 1:8e3af9643155 | 27 | init_(); |
sippasaeng | 4:4b28e4aa1742 | 28 | |
pokpongc | 0:ef2ee7458c37 | 29 | while(1){ |
sippasaeng | 4:4b28e4aa1742 | 30 | // continue; |
sippasaeng | 4:4b28e4aa1742 | 31 | if ( ! RfChip.PICC_IsNewCardPresent()) |
sippasaeng | 4:4b28e4aa1742 | 32 | { |
sippasaeng | 4:4b28e4aa1742 | 33 | continue; |
sippasaeng | 4:4b28e4aa1742 | 34 | } |
sippasaeng | 4:4b28e4aa1742 | 35 | |
sippasaeng | 4:4b28e4aa1742 | 36 | if ( ! RfChip.PICC_ReadCardSerial()) |
sippasaeng | 4:4b28e4aa1742 | 37 | { |
sippasaeng | 4:4b28e4aa1742 | 38 | continue; |
sippasaeng | 4:4b28e4aa1742 | 39 | } |
sippasaeng | 4:4b28e4aa1742 | 40 | |
sippasaeng | 4:4b28e4aa1742 | 41 | for (uint8_t i = 0; i < RfChip.uid.size; i++) |
sippasaeng | 4:4b28e4aa1742 | 42 | { |
sippasaeng | 4:4b28e4aa1742 | 43 | sum_x += RfChip.uid.uidByte[i]; |
sippasaeng | 4:4b28e4aa1742 | 44 | //pc.printf(" %X02", RfChip.uid.uidByte[i]); |
sippasaeng | 4:4b28e4aa1742 | 45 | } |
sippasaeng | 4:4b28e4aa1742 | 46 | /*pc.printf("\n\r"); |
sippasaeng | 4:4b28e4aa1742 | 47 | pc.printf(" UID_sum %d", sum_x); |
sippasaeng | 4:4b28e4aa1742 | 48 | pc.printf("\n\r");*/ |
sippasaeng | 4:4b28e4aa1742 | 49 | |
sippasaeng | 4:4b28e4aa1742 | 50 | if(sum_x == 461)RFID_Tag = 1; |
sippasaeng | 4:4b28e4aa1742 | 51 | else if(sum_x == 538)RFID_Tag = 2; |
sippasaeng | 4:4b28e4aa1742 | 52 | else if(sum_x == 598)RFID_Tag = 3; |
sippasaeng | 4:4b28e4aa1742 | 53 | else if(sum_x == 548)RFID_Tag = 4; |
sippasaeng | 4:4b28e4aa1742 | 54 | else RFID_Tag = 0; |
sippasaeng | 4:4b28e4aa1742 | 55 | |
sippasaeng | 4:4b28e4aa1742 | 56 | pc.printf("RFID_Tag : %d",RFID_Tag); |
sippasaeng | 4:4b28e4aa1742 | 57 | pc.printf("\n\r"); |
sippasaeng | 4:4b28e4aa1742 | 58 | sum_x = 0; |
sippasaeng | 4:4b28e4aa1742 | 59 | uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); |
sippasaeng | 4:4b28e4aa1742 | 60 | |
sippasaeng | 4:4b28e4aa1742 | 61 | // continue; |
sippasaeng | 4:4b28e4aa1742 | 62 | |
sippasaeng | 4:4b28e4aa1742 | 63 | |
sippasaeng | 4:4b28e4aa1742 | 64 | |
sippasaeng | 4:4b28e4aa1742 | 65 | |
sippasaeng | 4:4b28e4aa1742 | 66 | |
sippasaeng | 4:4b28e4aa1742 | 67 | |
sippasaeng | 4:4b28e4aa1742 | 68 | |
sippasaeng | 4:4b28e4aa1742 | 69 | |
sippasaeng | 4:4b28e4aa1742 | 70 | |
sippasaeng | 4:4b28e4aa1742 | 71 | |
pokpongc | 0:ef2ee7458c37 | 72 | pulse = temp_dial.getPulses()/2; |
pokpongc | 2:eb82f5cb5098 | 73 | if (pulse >= 350) |
pokpongc | 2:eb82f5cb5098 | 74 | pulse = 350; |
pokpongc | 2:eb82f5cb5098 | 75 | else if (pulse <= 0) |
pokpongc | 2:eb82f5cb5098 | 76 | pulse = 0; |
pokpongc | 2:eb82f5cb5098 | 77 | data[0] = 0x77; |
sippasaeng | 3:054df6da48b5 | 78 | data[1] = button_bus.read(); |
sippasaeng | 3:054df6da48b5 | 79 | data[2] = joy_bus.read(); |
pokpongc | 2:eb82f5cb5098 | 80 | if (pulse > 255){ |
sippasaeng | 3:054df6da48b5 | 81 | data[3] = pulse-255; |
sippasaeng | 3:054df6da48b5 | 82 | data[4] = 255; |
pokpongc | 2:eb82f5cb5098 | 83 | }else{ |
sippasaeng | 3:054df6da48b5 | 84 | data[3] = 0; |
sippasaeng | 3:054df6da48b5 | 85 | data[4] = pulse; |
pokpongc | 2:eb82f5cb5098 | 86 | } |
pokpongc | 2:eb82f5cb5098 | 87 | data[5] = 0x00; |
pokpongc | 2:eb82f5cb5098 | 88 | data[6] = 0x00; |
pokpongc | 2:eb82f5cb5098 | 89 | data[7] = 0x0A; |
sippasaeng | 3:054df6da48b5 | 90 | |
sippasaeng | 3:054df6da48b5 | 91 | //Data overwrite for serial transmit debug |
sippasaeng | 3:054df6da48b5 | 92 | /* data[0]= 0x00; |
sippasaeng | 3:054df6da48b5 | 93 | data[1]= 0x01; |
sippasaeng | 3:054df6da48b5 | 94 | data[2]= 0x02; |
sippasaeng | 3:054df6da48b5 | 95 | data[3]= 0x03; |
sippasaeng | 3:054df6da48b5 | 96 | data[4]= 0x04; |
sippasaeng | 3:054df6da48b5 | 97 | data[5]= 0x05; |
sippasaeng | 3:054df6da48b5 | 98 | data[6]= 0x06; |
sippasaeng | 3:054df6da48b5 | 99 | data[0]= 0x00; |
sippasaeng | 3:054df6da48b5 | 100 | */ |
sippasaeng | 3:054df6da48b5 | 101 | |
sippasaeng | 4:4b28e4aa1742 | 102 | // for (int i = 0; i<=7; i++) |
sippasaeng | 4:4b28e4aa1742 | 103 | // pc.putc(data[i]); |
pokpongc | 0:ef2ee7458c37 | 104 | } |
pokpongc | 0:ef2ee7458c37 | 105 | } |
pokpongc | 0:ef2ee7458c37 | 106 | |
pokpongc | 1:8e3af9643155 | 107 | |
pokpongc | 1:8e3af9643155 | 108 | void init_(){ |
sippasaeng | 4:4b28e4aa1742 | 109 | pc.baud(9600); |
sippasaeng | 4:4b28e4aa1742 | 110 | |
sippasaeng | 4:4b28e4aa1742 | 111 | RfChip.PCD_Init(); |
sippasaeng | 4:4b28e4aa1742 | 112 | |
pokpongc | 1:8e3af9643155 | 113 | a.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 114 | b.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 115 | c.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 116 | d.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 117 | e.mode(PullDown); |
pokpongc | 1:8e3af9643155 | 118 | f.mode(PullDown); |
sippasaeng | 4:4b28e4aa1742 | 119 | } |
sippasaeng | 4:4b28e4aa1742 | 120 | |
sippasaeng | 4:4b28e4aa1742 | 121 | void RFID_Tag_Read() |
sippasaeng | 4:4b28e4aa1742 | 122 | { |
sippasaeng | 4:4b28e4aa1742 | 123 | |
sippasaeng | 4:4b28e4aa1742 | 124 | |
sippasaeng | 4:4b28e4aa1742 | 125 | } |