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: TB6612FNG mbed BLE_nRF8001
Revision 3:a7f0b4b78648, committed 2014-11-12
- Comitter:
- ddrew73
- Date:
- Wed Nov 12 17:43:52 2014 +0000
- Parent:
- 2:5398a0de0780
- Commit message:
- :)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Nov 10 01:46:55 2014 +0000
+++ b/main.cpp Wed Nov 12 17:43:52 2014 +0000
@@ -1,31 +1,39 @@
+//THE INFAMOUS NET TRAP
+//Brought to you by Team LaTe
+
+
#include "mbed.h"
#include "TB6612.h"
#include "nRF8001.h"
#include "BLEPeripheral.h"
#include "BLECharacteristic.h"
-
+
+//Init
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
-//DigitalOut ultra_trigger(D8);
-//AnalogIn ultra_out(A0);
Serial serial(USBTX, USBRX); // tx, rx
+//BLE breakout
SPI spi(D11, D12, D13);
-
-//DigitalOut BIN2(D3);
-//DigitalOut BIN1(D4);
-//PwmOut PWMB(D6);
-//DigitalOut stdby(D9);
-//
-//TB6612 motorB(D6,D3,D4); // PWMA,AIN1,AIN2
-float distance = 0;
-float raw = 0;
-
DigitalInOut req(PTD0); // D10
DigitalInOut rdy(PTD4); // D2 needs a different pin
DigitalInOut rst(PTD5); // D9
+//Motor driver
+DigitalOut BIN2(D3);
+DigitalOut BIN1(D4);
+PwmOut PWMB(D6);
+DigitalOut stdby(D14);
+TB6612 motorB(D6,D3,D4); // PWMA,AIN1,AIN2
+
+//Ultrasonic
+float distance = 0;
+float raw = 0;
+int dropped = 0;
+DigitalOut ultra_trigger(D8);
+AnalogIn ultra_out(A0);
+
BLEProperty read = BLERead;
BLEProperty write = BLEWrite;
BLEProperty notify = BLENotify;
@@ -35,16 +43,17 @@
BLECharacteristic netDropChrc = BLECharacteristic("fbb3136a-fe49-445b-a612-2019d1b33a6c",read | write,1,1);
BLECharacteristic netDisarmedChrc = BLECharacteristic("f80fb006-0e8e-412c-8a92-19fe85328daa",read | write | notify,1,1);
-int main(){
+int main()
+{
serial.printf("starting something\r\n");
led1 = 1;
led2 = 1;
led3 = 1;
-// led1 = 0;
-// led2 = 0;
- // ultra_trigger = 1;
-// motorB = 0.0;
-// stdby = 1;
+
+ ultra_trigger = 1;
+ motorB = 0.0;
+ stdby = 1;
+
blePeripheral.setLocalName("NETTRAP");
blePeripheral.setDeviceName("net trap peripheral!");
blePeripheral.setAdvertisedServiceUuid(service.uuid());
@@ -59,30 +68,46 @@
netDropChrc.setValue(bufFalse);
netDisarmedChrc.setValue(bufFalse);
serial.printf("set up characteristic values\r\n");
-
+
blePeripheral.begin();
serial.printf("began peripheral supposedly\r\n");
- while(true) {
- blePeripheral.poll();
- }
-// while(true){
-
-// blePeripheral.poll();
-// motorB = 0.0;
-// // raw = ultra_out;
-// // distance = (ultra_out * 5) / 0.0098 ;
-// serial.printf("%1.3f %1.3f \n", raw, distance);
-// if (distance < 10){
-// motorB = 1.0;
-// }
-// wait(3);
- // }
-}
+ while(true) {
+
+
+ if (*netDropChrc.value() == 'f') {
+ if (*netDisarmedChrc.value()== 't') {
+ dropped = 1;
+ }
+ else {
+ dropped = 0;
+ }
+ }
+
+ else {
+ dropped = 1;
+ }
+
+ blePeripheral.poll();
+ motorB = 0.0;
+ raw = ultra_out;
+ distance = (ultra_out * 5) / 0.0098 ;
+ serial.printf("%1.3f %1.3f \n", raw, distance);
+ if (distance < 20 && dropped == 0) {
+ motorB = 1.0;
+ netDropChrc.setValue(bufTrue);
+ dropped = 1;
+ }
+ wait(1);
+ }
+
+}
+
+