![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test program
Dependencies: LSM9DS1_Library2 MotorV2 SRF05 Tracker2 mbed nRF24L01P
Fork of DUMP_TRUCK_SPR2017 by
Diff: main.cpp
- Revision:
- 10:cf77da9be0b8
- Parent:
- 5:dc4cf6cc24b3
- Child:
- 11:87f30625b213
--- a/main.cpp Tue Feb 14 14:46:37 2017 -0500 +++ b/main.cpp Tue Feb 28 21:11:48 2017 +0000 @@ -1,71 +1,18 @@ -#include "mbed.h" - -// Define buttons -InterruptIn button_red(p5); -InterruptIn button_green(p6); -InterruptIn button_blue(p7); - -// Define LED colors -PwmOut led_red(p21); -PwmOut led_green(p22); -PwmOut led_blue(p23); - -// Interrupt Service Routine to increment the red color -void inc_red() { +#include "DumpTruck.h" +DumpTruck dump(1); - float pwm; - - // Read in current PWM value and increment it - pwm = led_red.read(); - pwm += 0.1f; - if (pwm > 1.0f) { - pwm = 0.0f; - } - led_red.write(pwm); -} - -// Interrupt Service Routine to increment the green color -void inc_green() { - - float pwm; +/* +test code for driving and stopping when an object gets too close +to the dump truck. +*/ - // Read in current PWM value and increment it - pwm = led_green.read(); - pwm += 0.1f; - if (pwm > 1.0f) { - pwm = 0.0f; - } - led_green.write(pwm); -} - -// Interrupt Service Routine to increment the blue color -void inc_blue() { - - float pwm; - - // Read in current PWM value and increment it - pwm = led_blue.read(); - pwm += 0.1f; - if (pwm > 1.0f) { - pwm = 0.0f; +int main() { + while(1) { + if(dump.detect()) { + dump.stop(); + } else { + dump.drive(0.5f); + } } - led_blue.write(pwm); + } - -// Main loop -int main() { - - // Initialize all LED colors as off - led_red.write(0.0f); - led_green.write(0.0f); - led_blue.write(0.0f); - - // Define three interrupts - one for each color - button_red.fall(&inc_red); - button_green.fall(&inc_green); - button_blue.fall(&inc_blue); - - // Do nothing! We wait for an interrupt to happen - while(1) { - } -}