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)
also H08R6 module (IR sensor)
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 IT
I connected IR sensor module (H08R6) with Audio Speaker module (H07R3)
then began in writing code
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)
I have defined each module with a specific ID. The function of this ID is to define the module for another module
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
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 = number of samples for sine wave;
messageParams = 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).