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-src
Diff: main.cpp
- Revision:
- 2:7ca8b2154664
- Parent:
- 1:fad61b6e660b
- Child:
- 3:ce51f3857195
--- a/main.cpp Tue Aug 04 21:22:56 2015 +0000
+++ b/main.cpp Sun Aug 09 17:28:16 2015 +0000
@@ -10,6 +10,8 @@
IN4 - p25 --> OUT4 - MOTORB-
*/
+Timeout systicker;
+
PwmOut in1(p5);
PwmOut in2(p6);
@@ -22,8 +24,16 @@
DigitalOut LED(LED1);
Serial bluetooth(p9, p10);
-//Serial pc(USBTX, USBRX);
+Serial pc(USBTX, USBRX);
+
+void SysTick_handler()
+{
+ in1.write(0.5);
+ in2.write(0.5);
+ in3.write(0.5);
+ in4.write(0.5);
+}
/* Initialize timers for the H-bridge*/
int init_drive()
@@ -52,6 +62,50 @@
}
}
+void rxPCCallback()
+{
+ int i;
+ char c;
+ c = pc.getc();
+ switch (c) {
+ // Forward direction
+ case 'w':
+ in1.write(1.0);
+ in2.write(0.0);
+ in3.write(1.0);
+ in4.write(0.0);
+ systicker.attach(&SysTick_handler, 0.6);
+ break;
+ // Backward direction
+ case 's':
+ in1.write(0.0);
+ in2.write(1.0);
+ in3.write(0.0);
+ in4.write(1.0);
+ break;
+ // Left direction
+ case 'a':
+ in1.write(1.0);
+ in2.write(0.0);
+ in3.write(0.0);
+ in4.write(0.0);
+ break;
+ case 'd':
+ in1.write(0.0);
+ in2.write(1.0);
+ in3.write(0.0);
+ in4.write(0.0);
+ break;
+ default:
+ in1.write(0.5);
+ in2.write(0.5);
+ in3.write(0.5);
+ in4.write(0.5);
+ }
+
+
+}
+
/* Initialize the bluetooth module*/
int init_bluetooth()
{
@@ -59,7 +113,7 @@
//wait(0.2);
//bluetooth.printf("AT+NAMETHOR1\r\n");
bluetooth.attach(&rxCallback, Serial::RxIrq);
-
+
return 1;
}
@@ -78,17 +132,24 @@
int main()
{
+ pc.baud(9600);
+ //wait(0.2);
+ //bluetooth.printf("AT+NAMETHOR1\r\n");
+ pc.attach(&rxPCCallback, Serial::RxIrq);
init_drive();
- init_bluetooth();
+// init_bluetooth();
+
+
while(1) {
-/* if(pc.readable()) {
- bluetooth.putc(pc.getc());
- }
- if(bluetooth.readable()) {
- pc.putc(bluetooth.getc());
- }*/
- }
+
+ /* if(pc.readable()) {
+ bluetooth.putc(pc.getc());
+ }
+ if(bluetooth.readable()) {
+ pc.putc(bluetooth.getc());
+ }*/
+}
}
\ No newline at end of file