Transmitter collab codes

Dependencies:   mbed RGB-fun HC_SR04_Ultrasonic_Library xbee_lib

Files at this revision

API Documentation at this revision

Comitter:
pimani
Date:
Fri Apr 10 15:34:46 2020 +0000
Parent:
0:9cbddcc86466
Commit message:
Transmitter codes

Changed in this revision

HC_SR04_Ultrasonic_Library.lib Show annotated file Show diff for this revision Revisions of this file
RGB-fun.lib Show annotated file Show diff for this revision Revisions of this file
hcsr04.cpp Show annotated file Show diff for this revision Revisions of this file
hcsr04.h 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
diff -r 9cbddcc86466 -r 7fbedf384fe9 HC_SR04_Ultrasonic_Library.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HC_SR04_Ultrasonic_Library.lib	Fri Apr 10 15:34:46 2020 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/ejteb/code/HC_SR04_Ultrasonic_Library/#e0f9c9fb4cf3
diff -r 9cbddcc86466 -r 7fbedf384fe9 RGB-fun.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RGB-fun.lib	Fri Apr 10 15:34:46 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/sillevl/code/RGB-fun/#d10cfeb2f18e
diff -r 9cbddcc86466 -r 7fbedf384fe9 hcsr04.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hcsr04.cpp	Fri Apr 10 15:34:46 2020 +0000
@@ -0,0 +1,98 @@
+/* Copyright (c) 2013 Prabhu Desai
+ * pdtechworld@gmail.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+
+#include "hcsr04.h"
+
+
+HCSR04::HCSR04(PinName TrigPin,PinName EchoPin):
+    trigger(TrigPin), echo(EchoPin)
+{
+    pulsetime.stop();
+    pulsetime.reset();
+    echo.rise(this,&HCSR04::isr_rise);
+    echo.fall(this,&HCSR04::isr_fall);
+    trigger=0;
+}
+
+HCSR04::~HCSR04()
+{
+}
+
+void HCSR04::isr_rise(void)
+{
+    pulsetime.start();
+}
+void HCSR04::start(void)
+{
+    trigger=1;
+    wait_us(10);
+    trigger=0;
+}
+
+void HCSR04::isr_fall(void)
+{
+    pulsetime.stop();
+    pulsedur = pulsetime.read_us();
+    distance= (pulsedur*343)/20000;
+    pulsetime.reset();
+}
+
+void HCSR04::rise (void (*fptr)(void))
+{
+    echo.rise(fptr);
+}
+void HCSR04::fall (void (*fptr)(void))
+{
+    echo.fall(fptr);
+}
+
+unsigned int HCSR04::get_dist_cm()
+{
+    return distance;
+}
+unsigned int HCSR04::get_pulse_us()
+{
+    return pulsedur;
+}
+
+
+
+/*******************************************************
+   Here is a sample code usage
+********************************************************* 
+#include "hcsr04.h"
+HCSR04  usensor(p25,p6);
+int main()
+{
+    unsigned char count=0;
+    while(1) {
+        usensor.start();
+        wait_ms(500); 
+        dist=usensor.get_dist_cm();
+        lcd.cls();
+        lcd.locate(0,0);
+        lcd.printf("cm:%ld",dist );
+ 
+        count++;
+        lcd.locate(0,1);
+        lcd.printf("Distance =%d",count);
+        
+    }
+*/
\ No newline at end of file
diff -r 9cbddcc86466 -r 7fbedf384fe9 hcsr04.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hcsr04.h	Fri Apr 10 15:34:46 2020 +0000
@@ -0,0 +1,68 @@
+/* Copyright (c) 2013 Prabhu Desai
+ * pdtechworld@gmail.com
+ *
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+ * and associated documentation files (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge, publish, distribute,
+ * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all copies or
+ * substantial portions of the Software.
+ *
+ * For more details on the sensor :
+ * http://www.elecfreaks.com/store/hcsr04-ultrasonic-sensor-distance-measuring-module-p-91.html?zenid=pgm8pgnvaodbe36dibq5s1soi3
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+ * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef MBED_HCSR04_H
+#define MBED_HCSR04_H
+
+#include "mbed.h"
+
+/** HCSR04 Class(es)
+ */
+
+class HCSR04
+{
+public:
+    /** Create a HCSR04 object connected to the specified pin
+    * @param pin i/o pin to connect to
+    */
+    HCSR04(PinName TrigPin,PinName EchoPin);
+    ~HCSR04();
+
+    /** Return the distance from obstacle in cm
+    * @param distance in cms and returns -1, in case of failure
+    */
+    unsigned int get_dist_cm(void);
+    /** Return the pulse duration equal to sonic waves travelling to obstacle and back to receiver.
+    * @param pulse duration in microseconds.
+    */
+    unsigned int get_pulse_us(void);
+    /** Generates the trigger pulse of 10us on the trigger PIN.
+    */
+    void start(void );
+    void isr_rise(void);
+    void isr_fall(void);
+    void fall (void (*fptr)(void));
+    void rise (void (*fptr)(void));
+
+
+
+private:
+
+    Timer pulsetime;
+    DigitalOut  trigger;
+    InterruptIn echo;
+    unsigned int pulsedur;
+    unsigned int distance;
+};
+
+#endif
\ No newline at end of file
diff -r 9cbddcc86466 -r 7fbedf384fe9 main.cpp
--- a/main.cpp	Fri Aug 31 14:46:32 2012 +0000
+++ b/main.cpp	Fri Apr 10 15:34:46 2020 +0000
@@ -1,5 +1,20 @@
 #include "mbed.h"
 #include "xbee.h"
+#include "ultrasonic.h"
+#include "hcsr04.h"
+
+//sonars
+HCSR04  front1(p13,p12);
+HCSR04  front2(p14,p12);
+HCSR04  back1(p15,p12);
+HCSR04  back2(p16,p12);
+
+//IR sensors
+InterruptIn PIR_Left(p17);
+InterruptIn PIR_Right(p18);
+
+//SHOWING SENDING STATUS
+BusOUT sending(LED1,LED2,LED3,LED4);
 
 xbee xbee1(p9,p10,p11); //Initalise xbee_lib
 Serial pc(USBTX, USBRX); //Initalise PC serial comms