People Counter / Mbed 2 deprecated person_counter

Dependencies:   mbed mbed-rtos 4DGL-uLCD-SE HC_SR04_Ultrasonic_Library

Committer:
mmarine3
Date:
Wed Apr 22 21:22:28 2020 +0000
Revision:
9:f4f03767acc0
Parent:
8:c0a6a3363e43
Child:
10:7a939a54515e
Removed TOF sensor. Program prints Soanr data to LCD

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mmarine3 2:1ec843c95914 1 #include "mbed.h"
rmalik8 4:7d02b3f3bee6 2 #include "rtos.h"
mmarine3 2:1ec843c95914 3 #include "SDFileSystem.h"
mmarine3 2:1ec843c95914 4 #include "uLCD_4DGL.h"
rmalik8 3:b5cdd40e99e9 5 #include "XNucleo53L0A1.h"
rmalik8 4:7d02b3f3bee6 6 #include "ultrasonic.h"
mmarine3 8:c0a6a3363e43 7 #include "wave_player.h"
rmalik8 4:7d02b3f3bee6 8
rmalik8 3:b5cdd40e99e9 9 //#include <stdio.h>
mmarine3 2:1ec843c95914 10 #include <string>
mmarine3 2:1ec843c95914 11
rmalik8 4:7d02b3f3bee6 12 //I2C sensor pins
rmalik8 4:7d02b3f3bee6 13 #define VL53L0_I2C_SDA p28
rmalik8 4:7d02b3f3bee6 14 #define VL53L0_I2C_SCL p27
rmalik8 4:7d02b3f3bee6 15
mmarine3 9:f4f03767acc0 16 uLCD_4DGL uLCD(p13, p14, p12); // Initialize uLCD serial tx, serial rx, reset pin;
rmalik8 4:7d02b3f3bee6 17 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
mmarine3 9:f4f03767acc0 18 RawSerial BT(p9,p10); //Initialize Blutooth
mmarine3 9:f4f03767acc0 19 //Serial BT(p9,p10);
mmarine3 9:f4f03767acc0 20 AnalogOut speaker(p18); //Initialize speaker
mmarine3 9:f4f03767acc0 21 wave_player waver(&speaker); //Initialize Waveplayer
rmalik8 6:068146497fe6 22 Mutex mutex;
mmarine3 8:c0a6a3363e43 23 Mutex dist;
mmarine3 2:1ec843c95914 24 DigitalOut MyLED(LED1);
mmarine3 2:1ec843c95914 25
mmarine3 9:f4f03767acc0 26 int sdist = 0;
mmarine3 9:f4f03767acc0 27 void sonar(int distance)
rmalik8 4:7d02b3f3bee6 28 {
rmalik8 4:7d02b3f3bee6 29 //put code here to execute when the sonar distance has changed
mmarine3 9:f4f03767acc0 30 dist.lock();
mmarine3 9:f4f03767acc0 31 sdist = distance;
mmarine3 9:f4f03767acc0 32 dist.unlock();
mmarine3 9:f4f03767acc0 33 //printf("Sonar Distance:\r\n %d", sdist);
mmarine3 9:f4f03767acc0 34 }
rmalik8 4:7d02b3f3bee6 35
mmarine3 9:f4f03767acc0 36 ultrasonic mu(p30, p29, .1, 1, &sonar); //Set the trigger pin to p30 and the echo pin to p29
rmalik8 4:7d02b3f3bee6 37 //have updates every .1 seconds and a timeout after 1
mmarine3 9:f4f03767acc0 38 //second, and call sonar when the distance changes
mmarine3 9:f4f03767acc0 39
mmarine3 9:f4f03767acc0 40 void Sonar(void const* arguments)
mmarine3 9:f4f03767acc0 41 {
mmarine3 9:f4f03767acc0 42 mu.startUpdates();//start measuring the distance
mmarine3 9:f4f03767acc0 43 while(1)
mmarine3 9:f4f03767acc0 44 {
mmarine3 9:f4f03767acc0 45 //Do something else here
mmarine3 9:f4f03767acc0 46 mu.checkDistance(); //call checkDistance() as much as possible, as this is where
mmarine3 9:f4f03767acc0 47 //the class checks if dist needs to be called.
mmarine3 9:f4f03767acc0 48 Thread::wait(10);
rmalik8 4:7d02b3f3bee6 49 }
rmalik8 4:7d02b3f3bee6 50 }
mmarine3 2:1ec843c95914 51
mmarine3 8:c0a6a3363e43 52 //Thread to print the TOF and Sonar Values to the LCD
mmarine3 8:c0a6a3363e43 53 void LCD(void const *arguments)
mmarine3 8:c0a6a3363e43 54 {
mmarine3 8:c0a6a3363e43 55 Thread::wait(1000); //Wait for lidar and sonar setup
mmarine3 8:c0a6a3363e43 56 while(1)
mmarine3 8:c0a6a3363e43 57 {
mmarine3 8:c0a6a3363e43 58 uLCD.cls();
mmarine3 8:c0a6a3363e43 59 dist.lock();
mmarine3 9:f4f03767acc0 60 uLCD.printf("Sonar Distance:\n %d", sdist);
mmarine3 8:c0a6a3363e43 61 dist.unlock();
mmarine3 8:c0a6a3363e43 62 Thread::wait(1000); //Allow time to read value before reprint
mmarine3 9:f4f03767acc0 63
mmarine3 8:c0a6a3363e43 64 }
mmarine3 8:c0a6a3363e43 65 }
mmarine3 8:c0a6a3363e43 66
mmarine3 2:1ec843c95914 67 int main()
mmarine3 2:1ec843c95914 68 {
mmarine3 7:85d42006e380 69 uLCD.cls();
mmarine3 7:85d42006e380 70 uLCD.baudrate(BAUD_3000000);
mmarine3 7:85d42006e380 71 //wait(1.0);
mmarine3 7:85d42006e380 72
mmarine3 7:85d42006e380 73 //blu.attach(&parse_message,Serial::RxIrq);
mmarine3 8:c0a6a3363e43 74 //Was used in lab 3 to interupt if reading in a blutooth command
mmarine3 7:85d42006e380 75 //Thread t#(name_of_thread_function);
mmarine3 8:c0a6a3363e43 76 Thread t1(LCD);//Initialize LCD thread
mmarine3 9:f4f03767acc0 77 Thread t2(Sonar);//Initialize Sonar thread
rmalik8 4:7d02b3f3bee6 78
mmarine3 9:f4f03767acc0 79
mmarine3 9:f4f03767acc0 80 //mu.startUpdates();
mmarine3 8:c0a6a3363e43 81 /* //Code to read and play a file
mmarine3 7:85d42006e380 82 FILE *wave_file;
mmarine3 7:85d42006e380 83 //printf("Hello World");
mmarine3 7:85d42006e380 84 Thread::wait(1000);
mmarine3 7:85d42006e380 85 wave_file=fopen("/sd/test.wav","r");
mmarine3 7:85d42006e380 86 //serial_mutex.lock();
mmarine3 7:85d42006e380 87 if(wave_file==NULL) printf("file open error!\n\n\r");
mmarine3 7:85d42006e380 88 //serial_mutex.unlock();
mmarine3 7:85d42006e380 89 waver.play(wave_file);
mmarine3 7:85d42006e380 90 fclose(wave_file);
mmarine3 8:c0a6a3363e43 91 */
mmarine3 8:c0a6a3363e43 92
mmarine3 8:c0a6a3363e43 93 //Loop to validate the main loop is executing
mmarine3 8:c0a6a3363e43 94 while(1)
mmarine3 8:c0a6a3363e43 95 {
mmarine3 9:f4f03767acc0 96 //mu.checkDistance();
mmarine3 9:f4f03767acc0 97 //MyLED = !MyLED;
mmarine3 9:f4f03767acc0 98 //Thread::wait(100);
mmarine3 8:c0a6a3363e43 99 }
mmarine3 2:1ec843c95914 100 }