![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
mix
Dependencies: mbed Servo MFRC522 UniGraphic
main.cpp
- Committer:
- khimAS
- Date:
- 2018-12-18
- Revision:
- 12:4829da055199
- Parent:
- 11:3f04152789d8
- Child:
- 13:4d66521f6d89
File content as of revision 12:4829da055199:
#include "stdio.h" #include "mbed.h" #include "string" #include "Arial12x12.h" #include "Arial24x23.h" #include "Arial28x28.h" #include "Arial43x48_numb.h" #include "pict.h" #include "pavement_48x34.h" #include "TFT_MIPI.h" #include "SDFileSystem.h" #include "MFRC522.h" #define MF_RESET PC_6 #include "Servo.h" /////////////////////////////////////////////////////////////////////////////// Serial esp(PA_15,PB_7); Serial pc(SERIAL_TX, SERIAL_RX); MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET); PinName buspins[] = { PA_9, PC_7, PA_10, PB_3, PB_5, PB_4, PB_10, PA_8 }; TFT_MIPI myLCD(BUS_8, buspins, A3, A4, A2, A1, A0, "myLCD"); DigitalIn Sw[] = {PB_13, PB_14, PB_15, PB_2, PB_12,PA_11 }; Timer t; Servo myservo1(PC_8); Servo myservo2(PB_1); //Servo myservo3(A4); //Servo myservo4(A4); /////////////////////////////////////////////////////////////////////////////// unsigned short backgroundcolor=Orange; unsigned short foregroundcolor=Black; char orient=1; int i=0; int j=0; int k=0; int Pagejawjiw = 0; int state = 0; int main(){ //char Type; // char StD; // char Num; // char Jaw1[3]={}; // char Jaw2[3]={}; char *StudentID; uint8_t UIDCard[4]={}; pc.printf("starting...\n"); RfChip.PCD_Init(); myLCD.set_orientation(orient); int time; t.start(); myLCD.background(White); myLCD.foreground(foregroundcolor); myLCD.cls(); while(1){ char Type; char StD; char Num; char Jaw1[3]; char Jaw2[3]; if(Pagejawjiw == 0){ myLCD.background(backgroundcolor); myLCD.foreground(foregroundcolor); myLCD.Bitmap(150,45,180,180,data); myLCD.fillrect(0,320,500,280,Orange); time=t.read_us(); if(! RfChip.PICC_IsNewCardPresent()){ for(int i=200; i<=200;i++){ myLCD.locate(i,295); myLCD.printf("Please scan your Student ID card to start.");} for(int i=200; i>=2;i--){ myLCD.locate(i,295); myLCD.printf("Please scan your Student ID card to start.");} continue;} if ( ! RfChip.PICC_ReadCardSerial()){continue;} pc.printf("Studen's ID: "); for (uint8_t i = 0; i < RfChip.uid.size; i++){UIDCard[i] = RfChip.uid.uidByte[i];} if (UIDCard[0]==187 and UIDCard[1]==164 and UIDCard[2]==90 and UIDCard[3]==127){StudentID = "60340500033";StD='X';pc.printf("%s\n",StudentID);Pagejawjiw = 1;myLCD.cls();} else if (UIDCard[0]==60 and UIDCard[1]==135 and UIDCard[2]==56 and UIDCard[3]==59){StudentID = "60340500066";StD='Y';pc.printf("%s\n",StudentID);Pagejawjiw = 0;} else if (UIDCard[0]==152 and UIDCard[1]==63 and UIDCard[2]==31 and UIDCard[3]==137){pc.printf("card1");pc.printf("%s",Jaw1);pc.printf("%s\n",Jaw1[0]);pc.printf("%s\n",Jaw1[1]);pc.printf("%s\n",Jaw1[2]); esp.putc('A');esp.putc(Jaw1[0]);esp.putc(Jaw1[1]);esp.putc(Jaw1[2]);Jaw1[0]=' ';Jaw1[1]=' ';Jaw1[2]=' ';} //ฝาเปิด else if (UIDCard[0]==21 and UIDCard[1]==86 and UIDCard[2]==31 and UIDCard[3]==137){pc.printf("card2");pc.printf("%s",Jaw2);pc.printf("%s\n",Jaw2[0]); esp.putc('A');esp.putc(Jaw2[0]);esp.putc(Jaw2[1]);esp.putc(Jaw2[2]);Jaw2[0]=' ';Jaw2[1]=' ';Jaw2[2]=' ';} //ฝาเปิด else {StudentID="0"; pc.printf("%s\n",StudentID);} } else if (Pagejawjiw == 1) { if(i == 0 or Sw[2] == 0){ i++; switch(i){ case 1: myLCD.fillrect(0,50,500,500,White); myLCD.fillrect(0,0,500,50,Orange); myLCD.rect(155,70,320,120,Orange); myLCD.rect(155,130,320,180,Orange); myLCD.rect(155,190,320,240,Orange); myLCD.rect(155,250,320,300,Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.locate(160,15); myLCD.background(Orange); myLCD.foreground(Black); myLCD.printf("Select Mode"); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(162,85); myLCD.background(Yellow); myLCD.foreground(Green); myLCD.printf(" Document"); myLCD.locate(187,145); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("ID Card"); myLCD.locate(177,205); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Financial"); myLCD.locate(202,265); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Other"); wait(0.3); break; case 2: //myLCD.cls(); myLCD.fillrect(0,0,500,50,Orange); myLCD.rect(155,70,320,120,Orange); myLCD.rect(155,130,320,180,Orange); myLCD.rect(155,190,320,240,Orange); myLCD.rect(155,250,320,300,Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.locate(160,15); myLCD.background(Orange); myLCD.foreground(Black); myLCD.printf("Select Mode"); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(162,85); myLCD.background(White); myLCD.foreground(Black); myLCD.printf(" Document"); myLCD.locate(187,145); myLCD.background(Yellow); myLCD.foreground(Green); myLCD.printf("ID Card"); myLCD.locate(177,205); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Financial"); myLCD.locate(202,265); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Other"); wait(0.3); break; case 3: myLCD.fillrect(0,0,500,50,Orange); myLCD.rect(155,70,320,120,Orange); myLCD.rect(155,130,320,180,Orange); myLCD.rect(155,190,320,240,Orange); myLCD.rect(155,250,320,300,Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.locate(160,15); myLCD.background(Orange); myLCD.foreground(Black); myLCD.printf("Select Mode"); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(162,85); myLCD.background(White); myLCD.foreground(Black); myLCD.printf(" Document"); myLCD.locate(187,145); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("ID Card"); myLCD.locate(177,205); myLCD.background(Yellow); myLCD.foreground(Green); myLCD.printf("Financial"); myLCD.locate(202,265); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Other"); wait(0.3); break; case 4: myLCD.fillrect(0,0,500,50,Orange); myLCD.rect(155,70,320,120,Orange); myLCD.rect(155,130,320,180,Orange); myLCD.rect(155,190,320,240,Orange); myLCD.rect(155,250,320,300,Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.locate(160,15); myLCD.background(Orange); myLCD.foreground(Black); myLCD.printf("Select Mode"); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(162,85); myLCD.background(White); myLCD.foreground(Black); myLCD.printf(" Document"); myLCD.locate(187,145); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("ID Card"); myLCD.locate(177,205); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Financial"); myLCD.locate(202,265); myLCD.background(Yellow); myLCD.foreground(Green); myLCD.printf("Other"); wait(0.3); break; case 5: i=0; break; } } else if(Sw[0] == 0){ i--; switch(i){ case 0: i = 5; break; case 1: //myLCD.cls(); myLCD.fillrect(0,0,500,50,Orange); myLCD.rect(155,70,320,120,Orange); myLCD.rect(155,130,320,180,Orange); myLCD.rect(155,190,320,240,Orange); myLCD.rect(155,250,320,300,Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.locate(160,15); myLCD.background(Orange); myLCD.foreground(Black); myLCD.printf("Select Mode"); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(162,85); myLCD.background(Yellow); myLCD.foreground(Green); myLCD.printf(" Document"); myLCD.locate(187,145); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("ID Card"); myLCD.locate(177,205); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Financial"); myLCD.locate(202,265); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Other"); wait(0.3); break; case 2: myLCD.fillrect(0,0,500,50,Orange); myLCD.rect(155,70,320,120,Orange); myLCD.rect(155,130,320,180,Orange); myLCD.rect(155,190,320,240,Orange); myLCD.rect(155,250,320,300,Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.locate(160,15); myLCD.background(Orange); myLCD.foreground(Black); myLCD.printf("Select Mode"); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(162,85); myLCD.background(White); myLCD.foreground(Black); myLCD.printf(" Document"); myLCD.locate(187,145); myLCD.background(Yellow); myLCD.foreground(Green); myLCD.printf("ID Card"); myLCD.locate(177,205); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Financial"); myLCD.locate(202,265); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Other"); wait(0.3); break; case 3: myLCD.fillrect(0,0,500,50,Orange); myLCD.rect(155,70,320,120,Orange); myLCD.rect(155,130,320,180,Orange); myLCD.rect(155,190,320,240,Orange); myLCD.rect(155,250,320,300,Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.locate(160,15); myLCD.background(Orange); myLCD.foreground(Black); myLCD.printf("Select Mode"); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(162,85); myLCD.background(White); myLCD.foreground(Black); myLCD.printf(" Document"); myLCD.locate(187,145); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("ID Card"); myLCD.locate(177,205); myLCD.background(Yellow); myLCD.foreground(Green); myLCD.printf("Financial"); myLCD.locate(202,265); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Other"); wait(0.3); break; case 4: myLCD.fillrect(0,0,500,50,Orange); myLCD.rect(155,70,320,120,Orange); myLCD.rect(155,130,320,180,Orange); myLCD.rect(155,190,320,240,Orange); myLCD.rect(155,250,320,300,Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.locate(160,15); myLCD.background(Orange); myLCD.foreground(Black); myLCD.printf("Select Mode"); myLCD.set_font((unsigned char*) Arial24x23); myLCD.locate(162,85); myLCD.background(White); myLCD.foreground(Black); myLCD.printf(" Document"); myLCD.locate(187,145); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("ID Card"); myLCD.locate(177,205); myLCD.background(White); myLCD.foreground(Black); myLCD.printf("Financial"); myLCD.locate(202,265); myLCD.background(Yellow); myLCD.foreground(Green); myLCD.printf("Other"); wait(0.3); break; } } else if(Sw[4] == 0){ Pagejawjiw++; if(i==1){Type = '1';} else if(i==2){Type = '2';} else if(i==3){Type = '3';} else if(i==4){Type = '4';} wait(0.3); } } else if(Pagejawjiw == 2){ myLCD.background(White); myLCD.foreground(foregroundcolor); if(j == 0 or Sw[1] == 0){ switch(j){ case 0: j++; myLCD.cls(); myLCD.fillrect(0,0,500,50,Orange); myLCD.locate(150,15); myLCD.background(Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.printf("Select JorJew"); myLCD.fillrect(40,130,215,230,DarkGrey); myLCD.fillrect(265,130,440,230,DarkGrey); myLCD.fillcircle(127,182,40,Yellow); myLCD.fillcircle(347,182,40,White); myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); myLCD.background(White); myLCD.locate(106,160); myLCD.printf(" 1"); myLCD.locate(326,160); myLCD.printf(" 2"); wait(0.3); break; case 1: myLCD.fillrect(0,0,500,50,Orange); myLCD.locate(150,15); myLCD.background(Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.printf("Select JorJew"); myLCD.fillrect(40,130,215,230,DarkGrey); myLCD.fillrect(265,130,440,230,DarkGrey); myLCD.fillcircle(127,182,40,White); myLCD.fillcircle(347,182,40,Yellow); myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); myLCD.background(White); myLCD.locate(106,160); myLCD.printf(" 1"); myLCD.locate(326,160); myLCD.printf(" 2"); wait(0.3); break; } } else if(Sw[3] == 0){ myLCD.fillrect(0,0,500,50,Orange); myLCD.locate(150,15); myLCD.background(Orange); myLCD.set_font((unsigned char*) Arial28x28); myLCD.printf("Select JorJew"); myLCD.fillrect(40,130,215,230,DarkGrey); myLCD.fillrect(265,130,440,230,DarkGrey); myLCD.fillcircle(127,182,40,Yellow); myLCD.fillcircle(347,182,40,White); myLCD.set_font((unsigned char*) Arial43x48_numb, 46, 58, false); myLCD.background(White); myLCD.locate(106,160); myLCD.printf(" 1"); myLCD.locate(326,160); myLCD.printf(" 2"); wait(0.3); } else if(Sw[5] == 0){ Pagejawjiw = 1; wait(0.3); i = 0; myLCD.cls(); } else if(Sw[4] == 0){ Pagejawjiw++; if(j==1){Jaw1[0]=Type;Jaw1[1]=StD;Jaw1[2]=Num;pc.printf("%s",Jaw1);} else if(j==2){Jaw2[0]=Type;Jaw2[1]=StD;Jaw2[2]=Num;pc.printf("%s",Jaw2);} wait(0.3); myLCD.cls(); k=0; } } else if(Pagejawjiw == 3){ for(float p=1.0; p>=0.0; p -= 0.1) { myservo1 = p; myservo2 = 0.0; wait(0.2); break; } myLCD.background(White); myLCD.foreground(foregroundcolor); if(k==0 or Sw[1] == 0){ myLCD.fillrect(0,0,500,50,Orange); myLCD.locate(150,15); myLCD.background(Orange); myLCD.fillrect(125,90,355,230,Green); myLCD.set_font((unsigned char*) Arial28x28); myLCD.locate(165,130); myLCD.background(Green); myLCD.foreground(Black); myLCD.printf(" Take out"); myLCD.locate(190,170); myLCD.printf(" JorJew"); myLCD.fillrect(100,250,215,300,Yellow); myLCD.fillrect(265,250,380,300,Yellow); myLCD.locate(125,260); myLCD.background(Green); myLCD.foreground(Black); myLCD.printf("(A)"); myLCD.locate(290,260); myLCD.printf("(C)"); k++; wait(0.3); } else if((Sw[0] == 0)){ myLCD.cls(); Pagejawjiw++; wait(0.3); } else if((Sw[2] == 0)){ Pagejawjiw--; wait(0.3); j = 0; } } else if(Pagejawjiw == 4){ for(float p=1.0; p>=0.0; p -= 0.1) { myservo1 = 0.0; myservo2 = p; wait(0.2); break; } myLCD.cls(); myLCD.background(backgroundcolor); myLCD.foreground(foregroundcolor); myLCD.Bitmap(150,45,180,180,data); myLCD.fillrect(0,320,500,280,Orange); time=t.read_us(); Pagejawjiw = 0; i = 0; for(int i=2; i<350;i++){ myLCD.locate(i,295); myLCD.set_font((unsigned char*) Arial12x12); myLCD.printf("Love , Thank you"); } for(int i=350; i>=2;i--){ myLCD.locate(i,295); myLCD.set_font((unsigned char*) Arial12x12); myLCD.printf("Love , Thank you"); } wait(5); } } }