People Counter / Mbed 2 deprecated person_counter

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

Committer:
mmarine3
Date:
Wed Apr 22 17:30:31 2020 +0000
Revision:
7:85d42006e380
Parent:
6:068146497fe6
Child:
8:c0a6a3363e43
Added audio out pin and waveplayer. Added code to play a specified file to main function (ALL new code marked //NEW)

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"
rmalik8 4:7d02b3f3bee6 7
rmalik8 3:b5cdd40e99e9 8 //#include <stdio.h>
mmarine3 2:1ec843c95914 9 #include <string>
mmarine3 2:1ec843c95914 10
rmalik8 4:7d02b3f3bee6 11 //I2C sensor pins
rmalik8 4:7d02b3f3bee6 12 #define VL53L0_I2C_SDA p28
rmalik8 4:7d02b3f3bee6 13 #define VL53L0_I2C_SCL p27
rmalik8 4:7d02b3f3bee6 14
rmalik8 3:b5cdd40e99e9 15 uLCD_4DGL uLCD(p13, p14, p12); // serial tx, serial rx, reset pin;
rmalik8 4:7d02b3f3bee6 16 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
rmalik8 3:b5cdd40e99e9 17 DigitalOut shdn(p26);
rmalik8 4:7d02b3f3bee6 18 RawSerial BT(p9,p10);
rmalik8 4:7d02b3f3bee6 19 //Serial BT(p9,p10);
mmarine3 7:85d42006e380 20 AnalogOut speaker(p18); //NEW
mmarine3 7:85d42006e380 21 wave_player waver(&speaker);//NEW
rmalik8 6:068146497fe6 22 Mutex mutex;
mmarine3 2:1ec843c95914 23 DigitalOut MyLED(LED1);
mmarine3 2:1ec843c95914 24
rmalik8 4:7d02b3f3bee6 25 //needed for TOF
rmalik8 4:7d02b3f3bee6 26 static XNucleo53L0A1 *board=NULL;
mmarine3 2:1ec843c95914 27
rmalik8 4:7d02b3f3bee6 28 void dist(int distance)
rmalik8 4:7d02b3f3bee6 29 {
rmalik8 4:7d02b3f3bee6 30 //put code here to execute when the sonar distance has changed
rmalik8 4:7d02b3f3bee6 31
rmalik8 4:7d02b3f3bee6 32 }
rmalik8 4:7d02b3f3bee6 33
rmalik8 4:7d02b3f3bee6 34 ultrasonic mu(p30, p29, .1, 1, &dist); //Set the trigger pin to p30 and the echo pin to p29
rmalik8 4:7d02b3f3bee6 35 //have updates every .1 seconds and a timeout after 1
rmalik8 4:7d02b3f3bee6 36 //second, and call dist when the distance changes
rmalik8 4:7d02b3f3bee6 37
rmalik8 4:7d02b3f3bee6 38 void TOF(void const *arguments) {
rmalik8 4:7d02b3f3bee6 39 //initialize the TOF
rmalik8 4:7d02b3f3bee6 40 int status;
rmalik8 4:7d02b3f3bee6 41 uint32_t distance;
rmalik8 4:7d02b3f3bee6 42 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
rmalik8 4:7d02b3f3bee6 43 /* creates the 53L0A1 expansion board singleton obj */
rmalik8 4:7d02b3f3bee6 44 board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
rmalik8 4:7d02b3f3bee6 45 shdn = 0; //must reset sensor for an mbed reset to work
rmalik8 4:7d02b3f3bee6 46 wait(0.1);
rmalik8 4:7d02b3f3bee6 47 shdn = 1;
rmalik8 4:7d02b3f3bee6 48 wait(0.1);
rmalik8 4:7d02b3f3bee6 49 /* init the 53L0A1 board with default values */
rmalik8 4:7d02b3f3bee6 50 status = board->init_board();
rmalik8 4:7d02b3f3bee6 51 while (status) {
rmalik8 4:7d02b3f3bee6 52 //pc.printf("Failed to init board! \r\n");
rmalik8 4:7d02b3f3bee6 53 status = board->init_board();
rmalik8 4:7d02b3f3bee6 54 }
rmalik8 4:7d02b3f3bee6 55
rmalik8 4:7d02b3f3bee6 56 /*
rmalik8 4:7d02b3f3bee6 57
rmalik8 5:3ff2acbd08ab 58 How to get distance value
rmalik8 4:7d02b3f3bee6 59 status = board->sensor_centre->get_distance(&distance);
rmalik8 5:3ff2acbd08ab 60
rmalik8 5:3ff2acbd08ab 61 How you would print TOF to pc serial
rmalik8 4:7d02b3f3bee6 62 if (status == VL53L0X_ERROR_NONE) {
rmalik8 4:7d02b3f3bee6 63 pc.printf("D=%ld mm\r\n", distance);
rmalik8 4:7d02b3f3bee6 64 }
rmalik8 4:7d02b3f3bee6 65
rmalik8 4:7d02b3f3bee6 66 */
rmalik8 4:7d02b3f3bee6 67 }
mmarine3 2:1ec843c95914 68
mmarine3 2:1ec843c95914 69 int main()
mmarine3 2:1ec843c95914 70 {
mmarine3 7:85d42006e380 71 //NEW
mmarine3 7:85d42006e380 72 uLCD.cls();
mmarine3 7:85d42006e380 73 uLCD.baudrate(BAUD_3000000);
mmarine3 7:85d42006e380 74 //wait(1.0);
mmarine3 7:85d42006e380 75
mmarine3 7:85d42006e380 76 //blu.attach(&parse_message,Serial::RxIrq);
mmarine3 7:85d42006e380 77 //Was used to interupt if reading in a blutooth command
mmarine3 7:85d42006e380 78 //Thread t#(name_of_thread_function);
rmalik8 4:7d02b3f3bee6 79
mmarine3 7:85d42006e380 80
mmarine3 7:85d42006e380 81 FILE *wave_file;
mmarine3 7:85d42006e380 82 //printf("Hello World");
mmarine3 7:85d42006e380 83 Thread::wait(1000);
mmarine3 7:85d42006e380 84 wave_file=fopen("/sd/test.wav","r");
mmarine3 7:85d42006e380 85 //serial_mutex.lock();
mmarine3 7:85d42006e380 86 if(wave_file==NULL) printf("file open error!\n\n\r");
mmarine3 7:85d42006e380 87 //serial_mutex.unlock();
mmarine3 7:85d42006e380 88 waver.play(wave_file);
mmarine3 7:85d42006e380 89 fclose(wave_file);
mmarine3 2:1ec843c95914 90 }