Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HCSR04 mbed nRF24L01P
Revision 1:fca5426ac19e, committed 2018-04-23
- Comitter:
- divonjin
- Date:
- Mon Apr 23 00:22:58 2018 +0000
- Parent:
- 0:e8f4e84196c5
- Commit message:
- ff
Changed in this revision
| HCSR04.lib | Show annotated file Show diff for this revision Revisions of this file |
| mian.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/HCSR04.lib Sun Apr 22 20:18:52 2018 +0000 +++ b/HCSR04.lib Mon Apr 23 00:22:58 2018 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/rabad1/code/HCSR04/#5461d44a187c +http://mbed.org/teams/TVZ-Mechatronics-Team/code/HCSR04/#cf3e4e307d15
--- a/mian.cpp Sun Apr 22 20:18:52 2018 +0000
+++ b/mian.cpp Mon Apr 23 00:22:58 2018 +0000
@@ -8,14 +8,8 @@
#include "mbed.h"
#include "HCSR04.h"
-#include "nRF24L01P.h"
-
-
-
-#define PIN_TRIGGER (D10)
-#define PIN_ECHO (D9)
-#define PIN_PICTURE (D7)
-
+//#include "nRF24L01P.h"
+/*
#define TRANSFER_SIZE 4
//rf reciever module setting
@@ -23,79 +17,91 @@
DigitalOut myled1(LED_GREEN);
DigitalOut myled2(LED_RED);
-
-
+*/
-HCSR04 rangeFinder(PIN_TRIGGER, PIN_ECHO);
-DigitalOut buzzer(D2);
DigitalIn soundDete(D8);
DigitalIn touch(D4);
-DigitalOut Picamera(PIN_PICTURE);
+DigitalOut buzzer(D3);
+DigitalOut Picamera(D2);
Serial pc(USBTX,USBRX);
+Timer timer;
+HCSR04 rangeFinder(D5, D6);
float range;
-float tooClose=0.3;
+float tooClose=10;
int warning = 0;
int newevent =0;
void blink(){
+ pc.printf("blink\n\r");
buzzer = 1;
wait(.3);
buzzer = 0;
}
void takePic(){
- Picamera = 1;
+ pc.printf("take photo\n\r");
+ Picamera = 0; //0 to take pic
wait(.5);
- Picamera = 0;
- pc.printf("takephoto\n\r");
+ Picamera = 1; //1 not take pic
+ pc.printf("finish take photo\n\r");
}
void detectedsound(){
+ pc.printf("detecte sound\n\r");
if( soundDete == 1){
if(warning == 0){
+ pc.printf("sound too high\n\r");
warning = 1;
newevent = 1;
}
}
- }
+ }
void checkrange(){
- rangeFinder.startMeas();
- wait(0.1);
- if ( rangeFinder.getMeas(range) == RANGE_MEAS_VALID )
- {
- if ( range < tooClose ){
- if(warning == 0){
- warning = 1;
- newevent = 1;
- }
+ pc.printf("start check range\n\r");
+ timer.reset();
+ timer.start();
+ rangeFinder.startMeasurement();
+ while(!rangeFinder.isNewDataReady()){
+ }
+ range = rangeFinder.getDistance_cm();
+ pc.printf("range = %5.1f cm\n\r", range);
+ if ( range < tooClose ){
+ pc.printf("too cloth\n\r");
+ if(warning == 0){
+ warning = 1;
+ newevent = 1;
+ }
+ }
+ else{
+ if (soundDete == 0 & range>=tooClose){
+ pc.printf("not too cloth, clear warinig\n\r");
+ warning = 0;
}
- else{
- if (soundDete == 0){
- warning = 0;
- }
- }
- }
+ }
+ timer.stop();
+ wait_ms(500-timer.read_ms());
}
void shutter()
-{
+ {
if ( touch == 1){
+ pc.printf("shutter\n\r");
takePic();
}
-}
+ }
int main()
-{
-
-
+{
+ Picamera = 1;
+ rangeFinder.setRanges(3, 110);
+/*
char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE];
int txDataCnt = 0;
int rxDataCnt = 0;
my_nrf24l01p.powerUp();
-
// Display the (default) setup of the nRF24L01+ chip
pc.printf( "nRF24L01+ Frequency : %d MHz\r\n", my_nrf24l01p.getRfFrequency() );
pc.printf( "nRF24L01+ Output power : %d dBm\r\n", my_nrf24l01p.getRfOutputPower() );
@@ -109,27 +115,26 @@
my_nrf24l01p.setReceiveMode();
my_nrf24l01p.enable();
-
-
+*/
while (1)
{
pc.printf("init\n\r");
+ Picamera = 1;
detectedsound();
checkrange();
+ if ( newevent != 1){
+ shutter();
+ }
if ( warning == 1 ){
blink();
if ( newevent == 1){
takePic();
newevent =0;
}
- else{
- shutter();
- }
- }
-
-
- //this is for the transmission part of the code
+ }
+/*
+ //this is for the transmission part of the code
// If we've received anything over the host serial link...
if ( pc.readable() ) {
@@ -168,11 +173,6 @@
// Toggle LED2 (to help debug nRF24L01+ -> Host communication)
myled2 = !myled2;
}
-
-
-
-
-
-
+*/
}
}
\ No newline at end of file