Updated to latest version. Added in new version of the Siren
Dependencies: mbed-src
Fork of VolundrIntroCase2015 by
main.cpp
- Committer:
- tweaker1331
- Date:
- 2015-08-09
- Revision:
- 2:7ca8b2154664
- Parent:
- 1:fad61b6e660b
- Child:
- 3:ce51f3857195
File content as of revision 2:7ca8b2154664:
#include "mbed.h" /* MOTOR A ENA - p21 IN1 - p5 --> OUT1 - MOTORA+ IN2 - p6 --> OUT2 - MOTORA- MOTOR B ENB - p22 IN3 - p26 --> OUT3 - MOTORB+ IN4 - p25 --> OUT4 - MOTORB- */ Timeout systicker; PwmOut in1(p5); PwmOut in2(p6); PwmOut in3(p26); PwmOut in4(p25); DigitalOut en_a(p21); DigitalOut en_b(p22); DigitalOut LED(LED1); Serial bluetooth(p9, p10); 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() { // Set PWM frequency to 10 kHz in1.period_us(100); in2.period_us(100); in3.period_us(100); in4.period_us(100); /* Set enable pin high. NEVER set this pins low during driving. There are no protection diodes and with EN low, H-bridge is in Hi-Z mode. This can generate a high voltage that breaks the H-bridge.*/ en_a.write(1); en_b.write(1); return 1; } /*Handler for Bluetooth messages*/ void rxCallback() { char a; a = bluetooth.getc(); if(a == 'g') { LED = 1; } } 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() { bluetooth.baud(9600); //wait(0.2); //bluetooth.printf("AT+NAMETHOR1\r\n"); bluetooth.attach(&rxCallback, Serial::RxIrq); return 1; } /* Initialize ADC ports*/ int init_ADC() { return 1; } /* Initialize GPIO's*/ int init_GPIO() { return 1; } int main() { pc.baud(9600); //wait(0.2); //bluetooth.printf("AT+NAMETHOR1\r\n"); pc.attach(&rxPCCallback, Serial::RxIrq); init_drive(); // init_bluetooth(); while(1) { /* if(pc.readable()) { bluetooth.putc(pc.getc()); } if(bluetooth.readable()) { pc.putc(bluetooth.getc()); }*/ } }