Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //For 128x128 display
- //#include <TFT_ILI9163C.h>
- //#include <Adafruit_ST7735.h>
- //For drawBitmap function
- //#include <Adafruit_GFX.h>
- #include <TFT.h>
- #include <SPI.h>
- //Allow bitmap arrays to display from program memory instead of RAM
- #include <avr/pgmspace.h>
- // pin definition for the Uno
- #define cs 10
- #define dc 9
- #define rst 8
- // create an instance of the library
- TFT TFTscreen = TFT(cs, dc, rst);
- // char array to print to the screen
- char sensorPrintout[6];
- // TFT color definiton
- #define BLACK 0x0000
- #define BLUE 0x001F
- #define RED 0xF800
- #define GREEN 0x07E0
- #define CYAN 0x07FF
- #define MAGENTA 0xF81F
- #define YELLOW 0xFFE0
- #define WHITE 0xFFFF
- //Bitmap image has been converted into an array to store
- //pixel data in program memory of the arduino, as storing
- //it in RAM takes up too much space
- //Declaring data array for icon bitmap image as external variable
- //to be used in program memory
- //This is the fingerprint status locked icon
- static const uint8_t icon [] PROGMEM = {
- 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x3f,0xc0,0x0,0x0,0x0,
- 0x0,0x0,0x3,0xff,0xf8,0x0,0x0,0x0,
- 0x0,0x0,0x7,0xff,0xfe,0x0,0x0,0x0,
- 0x0,0x0,0x1f,0xc0,0x7f,0x80,0x0,0x0,
- 0x0,0x0,0x3e,0x0,0x7,0xc0,0x0,0x0,
- 0x0,0x0,0x7c,0x0,0x3,0xe0,0x0,0x0,
- 0x0,0x0,0xfd,0xff,0x81,0xf0,0x0,0x0,
- 0x0,0x0,0xff,0xff,0xe0,0xf0,0x0,0x0,
- 0x0,0x1,0xff,0xff,0xf8,0x78,0x0,0x0,
- 0x0,0x1,0xff,0x80,0x7c,0x38,0x0,0x0,
- 0x0,0x3,0xfc,0x0,0xe,0x3c,0x0,0x0,
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0x3e,0x7,0x87,0x0,0x0,
- 0x0,0xf,0x1e,0x3f,0xff,0x8f,0x0,0x0,
- 0x0,0xf,0x1e,0x1f,0xff,0x1f,0x0,0x0,
- 0x0,0xf,0xf,0x7,0xfc,0x3e,0x0,0x0,
- 0x0,0x7,0x87,0x80,0x0,0x7c,0x0,0x0,
- 0x0,0x7,0x87,0xe0,0x0,0xfc,0x0,0x0,
- 0x0,0x3,0xc3,0xf8,0x7,0xf8,0x0,0x0,
- 0x0,0x3,0xe1,0xff,0xff,0xe1,0x0,0x0,
- 0x0,0x1,0xe0,0x7f,0xff,0x83,0x0,0x0,
- 0x0,0x1,0xf8,0xf,0xfe,0x7,0x0,0x0,
- 0x0,0x0,0xfc,0x0,0x0,0xe,0x0,0x0,
- 0x0,0x0,0x3f,0x0,0x0,0x3c,0x0,0x0,
- 0x0,0x0,0x1f,0xe0,0x1,0xf8,0x0,0x0,
- 0x0,0x0,0x7,0xff,0xff,0xf0,0x0,0x0,
- 0x0,0x0,0x1,0xff,0xff,0xc0,0x0,0x0,
- 0x0,0x0,0x0,0x1f,0xfc,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
- 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0
- };
- //For fingerprint sensor (model GT-511C1R)
- #include "FPS_GT511C3.h"
- #include "SoftwareSerial.h"
- //FPS connected to pin 4 and 5 - see previous schemas
- FPS_GT511C3 fps(2, 3);
- //For thermistor (temperature sensor)
- int tempPin = 0;
- //For RGB LED
- #define ledRED 4
- #define ledGREEN 5
- //For buzzer
- #include "pitches.h"
- int buzzer = A1;
- //For ultrasonic sensor
- #include "SR04.h"
- #define TRIG_PIN 6
- #define ECHO_PIN 7
- SR04 sr04 = SR04(ECHO_PIN,TRIG_PIN);
- long a;
- //Defines variables for sensor calculations
- long duration;
- int distance;
- int safetyDistance;
- void setup() {
- Serial.begin(9600);
- pinMode(ledRED, OUTPUT); //Red LED
- pinMode(ledGREEN, OUTPUT); //Green LED
- pinMode(buzzer, OUTPUT);
- //Put this line at the beginning of every sketch that uses the GLCD:
- TFTscreen.begin();
- TFTscreen.setRotation(2); //Put orientation of display upside down
- // clear the screen with a black background
- TFTscreen.background(0, 0, 0);
- //Default green LED to on so it's green before the door is opened/alarm is set off
- digitalWrite(ledGREEN, HIGH); //Turn green LED on
- digitalWrite(ledRED, LOW); //Turn red LED off
- }
- void loop() {
- boolean fingerprintMatch = false; //fingerprintMatch false so ultrasonic sensor "listens" for door opening
- //Thermistor temp sensor calculations
- //double to 2 decimal places
- double tempReading = static_cast<double>(analogRead(tempPin));
- // This is OK
- double tempK = log(10000.0 * ((1024.0 / tempReading - 1.0)));
- //Temperature in kelvin
- tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK)) * tempK); // Temp Kelvin
- double tempC = tempK - 273.15; // Convert Kelvin to Celcius
- //double tempF = (tempC * 9.0) / 5.0 + 32.0; // Convert Celcius to Fahrenheit
- //Temperature as float with 2 decimal places
- float tempFAsFloat = static_cast<float>(tempK);
- float tempCAsFloat = static_cast<float>(tempC);
- ultrasonicOnOff();
- //Read the ECHO_PIN and return the sound wave travel time in ms
- duration = pulseIn(ECHO_PIN, HIGH);
- //Calculate the distance
- distance= duration*0.034/2;
- safetyDistance = distance;
- fingerprintMatch = false;
- if(safetyDistance <= 5) { //If distance 5cm or less
- boolean alarmSetOff = true;
- digitalWrite(ledGREEN, LOW); //Turn green LED off
- digitalWrite(ledRED, HIGH); //Turn red LED on
- digitalWrite(buzzer, HIGH); //Turn buzzer on
- TFTscreen.background(0, 0, 0); //Clear the screen with a black background
- displayLockScreen(); //Display "use fingerprint to unlock" message
- //Fingerprint sensor
- fps.Open(); //send serial command to initialise FPS
- fps.SetLED(true); //turn on LED so finger can be read
- delay(20);
- fps.SetLED(false);
- delay(20);
- fps.SetLED(true);
- delay(20);
- fps.SetLED(false);
- delay(20);
- fps.SetLED(true);
- digitalWrite(ECHO_PIN, LOW);
- else if(safetyDistance <= 5 && alarmSetOff, true) { //If distance 5cm or less but alarm already set off, LED stays red
- digitalWrite(ledGREEN, LOW); //Turn green LED off
- digitalWrite(ledRED, HIGH); //Turn red LED on
- }
- else{ //If distance > 5cm
- digitalWrite(ledGREEN, HIGH); //Turn green LED off
- digitalWrite(ledRED, LOW); //Turn red LED on
- }
- }
- }
- void displayTemp(float cTemp) //Function to display the temperature on the TFT display
- {
- // write the static text to the screen
- // set the font color to white
- TFTscreen.stroke(255, 255, 255);
- // set the font size
- TFTscreen.setTextSize(2);
- // write the text to the top left corner of the screen
- TFTscreen.text("Temperature:\n", 0, 25);
- TFTscreen.text("o", 110, 55);
- TFTscreen.text("C", 120, 65);
- // state the font size very large for the loop
- TFTscreen.setTextSize(3);
- //Force temp reading into a string so it can be put in a char array
- String sensorVal = String(cTemp, 2);
- // convert the reading to a char array
- String(sensorVal).toCharArray(sensorPrintout, 6);
- // set the font color
- TFTscreen.stroke(255, 255, 255);
- // print the sensor value
- TFTscreen.text(sensorPrintout, 20, 60);
- // wait for a moment
- delay(250);
- // erase the text you just wrote
- TFTscreen.stroke(0, 0, 0);
- TFTscreen.text(sensorPrintout, 20, 60);
- }
- void drawBitmap(int16_t x, int16_t y, //Adafruit GFX not supported in this case so function has to be declared manually
- //drawBitmap(x coordinates, y coordinates, name of bitmap, x resolution, x resolution, colour)
- const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) {
- int16_t i, j, byteWidth = (w + 7) / 8;
- uint8_t byte;
- for(j=0; j<h; j++) {
- for(i=0; i<w; i++) {
- if(i & 7) byte <<= 1;
- else byte = pgm_read_byte(bitmap + j * byteWidth + i / 8);
- if(byte & 0x80) TFTscreen.drawPixel(x+i, y+j, color);
- }
- }
- }
- void displayLockScreen() //Shows fingerprint lock screen on TFT display
- {
- TFTscreen.drawRect(0,0,128,128,WHITE);
- TFTscreen.setCursor(30,10);
- TFTscreen.setTextColor(RED);
- TFTscreen.setTextSize(2);
- TFTscreen.print("LOCKED");
- TFTscreen.setCursor(10,100);
- TFTscreen.setTextColor(WHITE);
- TFTscreen.setTextSize(1);
- TFTscreen.print("Waiting for valid \n fingerprint.");
- TFTscreen.drawBitmap(30,35,icon,60,60,WHITE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement