Driver for controlling Renishaw RenBuggy
Dependencies: SevenSegmentDisplay DCMotorDrive mbed MotorController
main.cpp@1:919b214c583c, 2013-12-24 (annotated)
- Committer:
- jf1452
- Date:
- Tue Dec 24 11:06:30 2013 +0000
- Revision:
- 1:919b214c583c
- Parent:
- 0:ae927e3c7264
- Child:
- 2:4180acdfa77a
Some more comments added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jf1452 | 0:ae927e3c7264 | 1 | /******************************************************************************* |
jf1452 | 0:ae927e3c7264 | 2 | * This program demonstrates how to drive the seven segment display * |
jf1452 | 0:ae927e3c7264 | 3 | * * |
jf1452 | 0:ae927e3c7264 | 4 | * Jon Fuge * |
jf1452 | 0:ae927e3c7264 | 5 | * V1.0 24/12/2013 First issue of code * |
jf1452 | 0:ae927e3c7264 | 6 | *******************************************************************************/ |
jf1452 | 0:ae927e3c7264 | 7 | |
jf1452 | 0:ae927e3c7264 | 8 | #include "mbed.h" |
jf1452 | 0:ae927e3c7264 | 9 | #include "SevenSegmentDisplay.h" |
jf1452 | 0:ae927e3c7264 | 10 | |
jf1452 | 0:ae927e3c7264 | 11 | uint8_t ui8Tens = 0, ui8Units = 0; |
jf1452 | 0:ae927e3c7264 | 12 | |
jf1452 | 1:919b214c583c | 13 | // Options to instantiate SevenSegmentDisplay are... |
jf1452 | 1:919b214c583c | 14 | // FADE: causes the number changes to fade in smoothly |
jf1452 | 1:919b214c583c | 15 | // INSTANT: causes the an instant number change |
jf1452 | 1:919b214c583c | 16 | // + FLASH: causes the display to flash |
jf1452 | 1:919b214c583c | 17 | SevenSegmentDisplay segmentled( FADE ); |
jf1452 | 0:ae927e3c7264 | 18 | |
jf1452 | 0:ae927e3c7264 | 19 | void attimeout(); //declare prototype for timeout handler. |
jf1452 | 0:ae927e3c7264 | 20 | |
jf1452 | 0:ae927e3c7264 | 21 | Ticker timeout; //Create an instance of class Ticker called timeout. |
jf1452 | 0:ae927e3c7264 | 22 | |
jf1452 | 0:ae927e3c7264 | 23 | int main() |
jf1452 | 0:ae927e3c7264 | 24 | { |
jf1452 | 1:919b214c583c | 25 | //segmentled.FlashRate(100); //Sets the flash rate to every 100ms |
jf1452 | 1:919b214c583c | 26 | //segmentled.FadeMode(FADE + FLASH); //Changes display mode to fade with flash |
jf1452 | 1:919b214c583c | 27 | //segmentled.FadeRate(10); // Sets the fade rate to 10ms intervals |
jf1452 | 0:ae927e3c7264 | 28 | |
jf1452 | 1:919b214c583c | 29 | // Set up interrupt to call attimeout() every half a second. |
jf1452 | 1:919b214c583c | 30 | timeout.attach_us(&attimeout, 500000); |
jf1452 | 1:919b214c583c | 31 | |
jf1452 | 1:919b214c583c | 32 | for(;;) {} // Loop forever (all the program uses interrupts. |
jf1452 | 0:ae927e3c7264 | 33 | } |
jf1452 | 0:ae927e3c7264 | 34 | |
jf1452 | 1:919b214c583c | 35 | void attimeout() |
jf1452 | 0:ae927e3c7264 | 36 | { |
jf1452 | 0:ae927e3c7264 | 37 | ui8Units ^= 0x80; |
jf1452 | 0:ae927e3c7264 | 38 | if ((ui8Units & 0x80) == 0) { |
jf1452 | 1:919b214c583c | 39 | ui8Units++; // "units" |
jf1452 | 1:919b214c583c | 40 | if (ui8Units > 36) { // cycle through entire range 0 -> 9, A -> Z |
jf1452 | 0:ae927e3c7264 | 41 | ui8Units = 0; // Reset the "units" to 0 |
jf1452 | 0:ae927e3c7264 | 42 | ui8Tens++; // Increment "tens" digit |
jf1452 | 1:919b214c583c | 43 | if (ui8Tens > 36) { // cycle through entire range 0 -> 9, A -> Z |
jf1452 | 0:ae927e3c7264 | 44 | ui8Tens = 0; // Reset the "tens" to 0 |
jf1452 | 0:ae927e3c7264 | 45 | } |
jf1452 | 0:ae927e3c7264 | 46 | } |
jf1452 | 0:ae927e3c7264 | 47 | } |
jf1452 | 1:919b214c583c | 48 | // Updates display with new values. |
jf1452 | 1:919b214c583c | 49 | segmentled.SevenSegmentDisplayChange(ui8Tens, ui8Units); |
jf1452 | 1:919b214c583c | 50 | } |