The story began when I saw our neighbor in the house next to us as he was parking the car in the designated place, and he was finding it difficult to estimate the distance between him and the car behind him. So I had an idea to put an alarm sensor that would warn the driver of the distance between him and the car behind him
The idea was to use H07R3 module (Audio Speaker)
https://hexabitz.com/product/audio-speaker-and-headphone-jack-h07r3x/
also H08R6 module (IR sensor)
https://hexabitz.com/product/1d-lidar-ir-sensor-h08r6x/
H08R6 module (IR sensor) will read distance between him and the car
then send message to H07R3 module (Audio Speaker) to play song,
The volume level will increase as the distance decrease between two cars.
HOW TO BUILD ITI connected IR sensor module (H08R6) with Audio Speaker module (H07R3)
then began in writing code
Explain code
- First
I defined fixed topology in both modules (H08R6, H07R3), It describes the connection of the modules between them.
Note : P08R6 module is same H08R6 module but different form
H08R6 module (IR sensor)
P08R6 module (IR sensor)
- Second
I have defined each module with a specific ID. The function of this ID is to define the module for another module
example :
Suppose if we had three modules (module1, module2, module3), module 1 will send a message to module 2, How module2 will know from the source of this message (module1 or module2) ?
answer : module2 will know the source this message through ID which send it module1 with this message.
ID module1 (H08R6) is 1
ID module2 (H07R3) is 2
in this part module2 (H07R3) will receive a messages on port3, so I reversed it
- Third
in main.c file :
The sensor unit is set to unit cm, then I enabled DMA in order to transmit data from sensor to memory
inside for loop :
- call function AbsDistanceToColor(sensor) function of this function is return a value depending on a sensor value, and Assignment return value to state_sensor variable
- add delay time, it is time between One message and another
- inside switch() we will check state_sensor value
- message explain :
messageParams[0 -> 3] = frequency;
messageParams[4] = number of samples for sine wave;
messageParams[5] = play sine wave for specified time;
SendMessageToModule (2, CODE_H07R3_PLAY_SINE, 6);
2 is ID module2 (H07R3)
CODE_H07R3_PLAY_SINE is code message (through it module2 (H07R3) will know what execute) here we say to module2 (H07R3) play sine wave
6 number of messageparams
note : their is not code for (Audio Speaker module H07R3) because execute code external by messages which will arrive from IR sensor module (H08R6).
Comments