Uses Arduino to take signals from a Lidar Lite v3 to scan a room. Arduino picks up a change in distance. Sends a signal to the k64. That k64 sets off sounds connected to a speaker. Those sounds are prerecorded on a flash drive. The k64 also flashes and LED that will flash until a turn off signal UDP packet is sent to it. It also sends an alarm UDP packet to another K64 that has flashing LEDs.

Dependencies:   EthernetInterface LidarLitev2 SDFileSystem Servo mbed-rtos mbed wave_player

Need to use this program also.

https://developer.mbed.org/users/dereklstinson/code/Motion_Secure_Client_IUPUI/

Files at this revision

API Documentation at this revision

Comitter:
dereklstinson
Date:
Fri Dec 16 00:52:05 2016 +0000
Commit message:
Version .01 Alpha had to use an Arduino to read the Lidar sensor. Any sensor will work as long as you pass a signal to the K64. It will play sounds that you have on your flash card. I used wav files I made from various sources involving security

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
LidarLitev2.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
Servo.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
wave_player.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a76470827116 EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Fri Dec 16 00:52:05 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
diff -r 000000000000 -r a76470827116 LidarLitev2.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LidarLitev2.lib	Fri Dec 16 00:52:05 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/sventura3/code/LidarLitev2/#b0deebd36eb3
diff -r 000000000000 -r a76470827116 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Fri Dec 16 00:52:05 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
diff -r 000000000000 -r a76470827116 Servo.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Fri Dec 16 00:52:05 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/simon/code/Servo/#36b69a7ced07
diff -r 000000000000 -r a76470827116 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Dec 16 00:52:05 2016 +0000
@@ -0,0 +1,227 @@
+/*------------------------------------------------------------------------------------*/
+/*  Ethernet UDP Server (to be used with Ethernet_UDP_client)                         */
+/*------------------------------------------------------------------------------------*/
+
+/*--COMPANY-----AUTHOR------DATE------------REVISION----NOTES-------------------------*/
+/*  NXP         mareikeFSL  2015.12.23      rev 1.0     initial                       */
+/*                                                                                    */
+/*------------------------------------------------------------------------------------*/
+/*  This "Hello World" program is used in conjunction with the Ethernet_UDP_client    */
+/*  program. It communicates between two FRDM-K64F boards via the Ethernet protocol.  */
+/*  To use this program, you need to do the following:                                */
+/*      - Connect an Ethernet cable between two FRDM-K64F boards (a crossover cable   */
+/*        is not required).                                                           */
+/*      - Flash one board with Ethernet_UDP_client and the other with                 */
+/*        Ethernet_UDP_server                                                         */
+/*      - [optional] If you would like to see the "Hello World" output on your        */
+/*        monitor, install and open a terminal. Tera Term is used in the Wiki for     */
+/*        this program.                                                               */
+/*------------------------------------------------------------------------------------*/
+
+
+/*--INCLUDES----------------------------------------------------------------------------*/
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "SDFileSystem.h"
+#include "wave_player.h"
+#include "Servo.h"
+#include "LidarLitev2.h"
+#include "rtos.h"
+#include "eth_arch.h"
+/*--DEFINES-----------------------------------------------------------------------------*/
+#define SWEEP_TIME .1
+
+
+/*--CONSTANTS---------------------------------------------------------------------------*/
+Queue<uint32_t, 5> queue;
+const int PORT = 7;                             //arbitrary port
+
+static const char* SERVER_IP = "192.168.1.101"; //IP of server board
+static const char* MASK = "255.255.255.0";      //mask
+static const char* GATEWAY = "192.168.1.1";     //gateway
+
+
+/*--INITS-------------------------------------------------------------------------------*/
+Serial pc(USBTX, USBRX);        //create PC interface
+EthernetInterface eth;          //create ethernet
+UDPSocket server;               //creat server
+Endpoint client;                //create endpoint
+
+DigitalOut alarmconfirm(PTD0);
+DigitalIn alarmcheckpin(PTD1);
+DigitalOut red(LED_RED);        //debug led
+DigitalOut green(LED_GREEN);    //debug led
+DigitalOut led(D12);
+SDFileSystem sd(PTE3,PTE1, PTE2, PTE4, "sd"); //SD card
+
+AnalogOut DACout(DAC0_OUT);
+
+wave_player waver(&DACout);
+
+
+Timer dt;
+/*--VARIABLES---------------------------------------------------------------------------*/
+int n;                  //size of received message
+char counter[1] = {0};  //sample receive/send buffer
+int i=0;
+int sweep_flag =0;
+int waiting_answer = 0;
+Ticker flashes;
+//Ticker IO;
+
+int someflag=0;
+ FILE *wave_file;
+/*--FUNCTION DECLARATIONS---------------------------------------------------------------*/
+int sensoralarmcheck(void);
+void alarmCheck(char x);
+void alarmLight(void);
+void alarmSound(void);
+void init_usb(void);    //initializes pc.printf if required
+void init_eth(void);    //initializes Ethernet
+void receive(void);     //receives packets
+void queue_isr();
+int main(void);         //main
+void flashingstuff();
+
+
+/*--FUNCTION DEFINITIONS----------------------------------------------------------------*/
+/****************************************************************************************/
+void flashingstuff(){
+    if ((someflag==1) || (red==0)){
+        red=!red;
+        led=!led;
+    }  
+    }
+/*queue_thread**************************************************************************/
+
+
+/*****************************************************************************INIT_USB***/
+void init_usb(void)
+{
+    pc.baud(9600);    //baud
+    
+}   //end init_usb()
+
+/*****************************************************************************INIT_ETH***/
+void init_eth(void)
+{
+    pc.printf("Initializing Ethernet\r\n");
+    eth.init(SERVER_IP, MASK, GATEWAY);                                         //set up IP
+    eth.connect();                                                              //connect ethernet
+    pc.printf("\nSERVER - Server IP Address is %s\r\n", eth.getIPAddress());    //get server IP address;
+    
+    server.bind(PORT);                                                          //bind server
+    pc.printf("Initialization Complete\n\r");    
+}   //end init_eth()
+
+/******************************************************************************RECEIVE***/
+void receive(void)
+{ 
+   int herewego=0;
+     
+     pc.printf("\nSERVER - Waiting for UDP packet...\r\n");                                      //wait for packet
+    n = server.receiveFrom(client, counter, sizeof(counter));                                   //receive message from client
+    counter[n] = '\0';                                                                          //add \0 to end of message
+    
+   
+    pc.printf("SERVER - Received '%i' from client %s\r\n", counter[0], client.get_address());   //print message and client
+    alarmCheck(counter[0]);
+  herewego = sensoralarmcheck();
+ 
+    if (herewego==1||waiting_answer==1){
+        waiting_answer =1;
+        printf("Lidar Caught something\r\n");
+        counter[0]='z';
+         }
+    pc.printf("SERVER - Sending '%i' back to client %s\r\n", counter[0], client.get_address()); //print sending back
+    wait(.5f);
+   
+    server.sendTo(client, counter, n);            
+                                                  //send message
+  }   //end receive()
+
+/***Alarm Check***************************************************************************/
+void alarmCheck(char x){
+  pc.printf("\n\rInto alarm check\r\n");
+    if (x == 'x') {
+        alarmconfirm =0;
+        waiting_answer=0;
+        someflag=0;
+        }
+    if (x!='b') return;
+    alarmLight();
+    alarmSound();
+    
+ }
+ 
+ 
+ 
+ 
+/**Alarm_Sound****************************************************************************/
+
+void alarmSound(void){
+    
+        if (i==0){
+        wave_file=fopen("/sd/intuder_detected.wav","r");
+        } 
+        else if (i==1){
+             wave_file=fopen("/sd/alarm.wav","r");
+             }
+             else if(i==2){
+                  wave_file=fopen("/sd/20seconds.wav","r");
+                  }
+                  else if (i==3){
+                       wave_file=fopen("/sd/dangerous.wav","r");
+                       }
+                       else if (i==4){
+                            wave_file=fopen("/sd/searching.wav","r");
+                            }
+                            else if (i==5){
+                                 wave_file=fopen("/sd/scanning.wav","r");
+                                 }
+           
+             
+        waver.play(wave_file);
+        fclose(wave_file);
+        i++;
+        if(i>=6){
+            i=0;
+            }
+        }
+       
+            
+/**Alarm_lights**************************************************************************/
+void alarmLight(void){
+    
+     someflag = 1;
+           wait(0.1f);
+     }
+    
+/***lidarSweep****************************************************************************/
+   int sensoralarmcheck(void){
+   if (alarmcheckpin){
+       alarmLight();
+       alarmSound();
+       return 1;
+       }
+       return 0;
+       }
+/*********************************************************************************MAIN***/
+int main(void)
+{
+
+    red = 1;
+    green = 0;      //server
+
+    init_usb();     //initialize the PC interface
+    init_eth();     //initialize the Ethernet connection
+     flashes.attach(&flashingstuff,.1);
+
+    while (true)    //repeat forever
+    {        
+           
+             receive();  //wait for message
+       
+    }
+
+}   //end main()
diff -r 000000000000 -r a76470827116 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Dec 16 00:52:05 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#c825593ece39
diff -r 000000000000 -r a76470827116 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Dec 16 00:52:05 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file
diff -r 000000000000 -r a76470827116 wave_player.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/wave_player.lib	Fri Dec 16 00:52:05 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/sravet/code/wave_player/#acc3e18e77ad