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: mbed mbed-rtos Motor HC_SR04_Ultrasonic_Library
Revision 0:a36c747fb7e0, committed 2019-12-09
- Comitter:
- tzahi12345
- Date:
- Mon Dec 09 04:49:58 2019 +0000
- Commit message:
- a commit;
Changed in this revision
diff -r 000000000000 -r a36c747fb7e0 HC_SR04_Ultrasonic_Library.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HC_SR04_Ultrasonic_Library.lib Mon Dec 09 04:49:58 2019 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/ejteb/code/HC_SR04_Ultrasonic_Library/#e0f9c9fb4cf3
diff -r 000000000000 -r a36c747fb7e0 Motor.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Motor.lib Mon Dec 09 04:49:58 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/Motor/#f265e441bcd9
diff -r 000000000000 -r a36c747fb7e0 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Dec 09 04:49:58 2019 +0000
@@ -0,0 +1,153 @@
+#include "mbed.h"
+#include "Motor.h"
+#include "rtos.h"
+#include "ultrasonic.h"
+
+// THREADS
+
+Thread dispenseThread;
+
+// BLUETOOTH
+
+Serial blue(p28,p27);
+
+// MOTOR
+
+Motor ketch(p21, p11, p12); // pwm, fwd, rev
+
+// DEBUG
+
+DigitalOut debugLED(LED1);
+DigitalOut errorLED(LED4);
+
+// SONAR
+int global_distance;
+
+void dist(int a_distance)
+{
+ global_distance = a_distance;
+}
+ultrasonic mu(p6, p7, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9
+ //have updates every .1 seconds and a timeout after 1
+ //second, and call dist when the distance changes
+// Servo ketch(p21);
+
+
+bool ketchupDispensing = false;
+
+void dispenseKetchup() {
+ if (ketchupDispensing) {
+ // already dispensing the ketch
+ return;
+ }
+
+ // set dispensing flag
+ ketchupDispensing = true;
+
+ //dispense
+ ketch.speed(1.0f);
+}
+
+void stopDispenseKetchup() {
+ if (!ketchupDispensing) {
+ // not dispensing, you can't stop no ketch, so just return
+ return;
+ }
+
+ // unset dispensing flag
+ ketchupDispensing = false;
+ ketch.speed(0.0f);
+
+ // turns debug LEDs off just in case
+ debugLED = 0;
+ errorLED = 0;
+}
+
+void dispenseSomeKetchup() {
+ if (global_distance < 150) {
+ debugLED = 1;
+ printf("In thread, dispensing ketchup\n");
+ dispenseKetchup();
+ Thread::wait(1750);
+ stopDispenseKetchup();
+ printf("Stopped dispense\n");
+ debugLED = 0;
+ } else {
+ debugLED = 1;
+ errorLED = 1;
+ Thread::wait(1750);
+ debugLED = 0;
+ errorLED = 0;
+ }
+}
+
+void dispenseMuchKetchup() {
+ if (global_distance < 150) {
+ debugLED = 1;
+ printf("In thread, dispensing ketchup\n");
+ dispenseKetchup();
+ Thread::wait(3500);
+ stopDispenseKetchup();
+ printf("Stopped dispense\n");
+ debugLED = 0;
+ } else {
+ debugLED = 1;
+ errorLED = 1;
+ Thread::wait(1750);
+ debugLED = 0;
+ errorLED = 0;
+ }
+}
+
+void dispenseKetchupInfinitely() {
+ if (global_distance < 150) {
+ debugLED = 1;
+ printf("In thread, dispensing ketchup continuous\n");
+ dispenseKetchup();
+ } else {
+ debugLED = 1;
+ errorLED = 1;
+ Thread::wait(1750);
+ debugLED = 0;
+ errorLED = 0;
+ }
+}
+
+int main()
+{
+ mu.startUpdates();//start measuring the distance
+ debugLED = 1;
+ ketch.speed(1.0f);
+ Thread::wait(1000);
+ ketch.speed(0.0f);
+ debugLED = 0;
+ while(1) {
+ //Do something else here
+ mu.checkDistance(); //call checkDistance() as much as possible, as this is where
+ //the class checks if dist needs to be called.
+ char bnum;
+ if (blue.getc()=='!') {
+ if (blue.getc()=='B') { //button data
+ bnum = blue.getc(); //button number
+ printf("bnum is %c", bnum);
+ if ((bnum>='1')&&(bnum<='4')) //is a number button 1..4
+ {
+ if (bnum == '1') {
+ // dispense some ketchup
+ printf("Starting thread\n");
+ dispenseThread.start(dispenseSomeKetchup);
+ } else if (bnum == '2') {
+ // dispense a lot of ketchup
+ dispenseMuchKetchup();
+ } else if (bnum == '3') {
+ // infinite ketchup
+ dispenseKetchupInfinitely();
+ } else if (bnum == '4') {
+ // stop dispense ketchup
+ stopDispenseKetchup();
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff -r 000000000000 -r a36c747fb7e0 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Mon Dec 09 04:49:58 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed-rtos/#5713cbbdb706
diff -r 000000000000 -r a36c747fb7e0 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Dec 09 04:49:58 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file