(DA) Internet of Things and Smart Electronics- ELE3006M2122
/
ObjectDetection_LiamCox
First Draft, serial print change based on distance
main.cpp
- Committer:
- liam94
- Date:
- 2021-12-04
- Revision:
- 0:506531d0531c
- Child:
- 1:a1795335ef8c
File content as of revision 0:506531d0531c:
#include "mbed.h" #include "ultrasonic.h" #include "N5110.h" // rows,cols int sprite[8][5] = { { 0,0,1,0,0 }, { 0,1,1,1,0 }, { 0,0,1,0,0 }, { 0,1,1,1,0 }, { 1,1,1,1,1 }, { 1,1,1,1,1 }, { 1,1,0,1,1 }, { 1,1,0,1,1 }, }; // VCC,SCE,RST,D/C,MOSI,SCLK,LED N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); //Set LCD Pins ultrasonic mu(PTA0, PTD0, .1, 1); //Set the trigger pin to PTA0 and the echo pin to PTD0 //have updates every .1 seconds and a timeout after 1 //second, and call dist when the distance changes int main() { // initialise lcd lcd.init(); // set lcd contrast lcd.setContrast(0.4); lcd.clear(); mu.startUpdates();//start mesuring the distance while(1) { // x origin, y origin, rows, cols, sprite lcd.drawSprite(20,6,8,5,(int *)sprite); lcd.refresh(); wait(5.0); mu.checkDistance(); //call checkDistance() as much as possible, as this is where //the class checks if dist needs to be called. if (distance > 1000){ // check if somebody is infront of the sensor <--- needs resolving lcd.clear(); // if nobody present then clear screen and turn backlight off lcd.setBrightness(0.0); printf("sleep"); // print sleep for debugging } } }