Driver for controlling Renishaw RenBuggy
Dependencies: SevenSegmentDisplay DCMotorDrive mbed MotorController
main.cpp
- Committer:
- jf1452
- Date:
- 2014-01-15
- Revision:
- 3:0dd99309381e
- Parent:
- 2:4180acdfa77a
- Child:
- 4:64d065d6d072
File content as of revision 3:0dd99309381e:
/******************************************************************************* * This program demonstrates how to drive the seven segment display * * * * Jon Fuge * * V1.0 24/12/2013 First issue of code * *******************************************************************************/ #include "mbed.h" #include "SevenSegmentDisplay.h" #include "MotorController.h" uint16_t u16LeftSpeed = 0, u16RightSpeed = 0; // Options to instantiate SevenSegmentDisplay are... // FADE: causes the number changes to fade in smoothly // INSTANT: causes the an instant number change // + FLASH: causes the display to flash SevenSegmentDisplay segmentled( FADE ); MotorController RenBuggy(p5, p7, p6, p8); DigitalIn LFast(p9), LSlow(p12), RFast(p15), RSlow(p18); void attimeout(); //declare prototype for timeout handler. Ticker timeout; //Create an instance of class Ticker called timeout. int main() { LFast.mode(PullUp); LSlow.mode(PullUp); RFast.mode(PullUp); RSlow.mode(PullUp); timeout.attach(&attimeout, 3); // LeftMotor.SetMotorPwmAndRevolutions(18000,32); for(;;) { } // Loop forever (the program uses interrupts) } void attimeout() { int MotorConv = 0; static int Flip = 0; if ((RFast == 0) && (u16RightSpeed < PWM_PERIOD * 1000)) { u16RightSpeed += 15; // RightMotor.SetMotorPwm(u16RightSpeed); } if ((RSlow == 0) && (u16RightSpeed > 0)) { u16RightSpeed -= 15; // RightMotor.SetMotorPwm(u16RightSpeed); } if ((LFast == 0) && (u16LeftSpeed < PWM_PERIOD * 1000)) { u16LeftSpeed += 15; // LeftMotor.SetMotorPwm(u16LeftSpeed); } if ((LSlow == 0) && (u16LeftSpeed > 0)) { u16LeftSpeed -= 15; // LeftMotor.SetMotorPwm(u16LeftSpeed); } // Updates display with new values. if (Flip++ == 0) MotorConv = RenBuggy.LeftReadOdometer(); else { MotorConv = RenBuggy.RightReadOdometer(); Flip = 0; } //MotorConv = RenBuggy.LeftReadOdometer(); segmentled.DisplayInt(MotorConv); }