The example program for RenBED to deomonstrate ticker and the Seven Segment Display Driver
Dependencies: SevenSegmentDisplay mbed
Fork of RenBEDCounter by
main.cpp@2:249f10554a91, 2014-02-10 (annotated)
- Committer:
- jf1452
- Date:
- Mon Feb 10 08:35:52 2014 +0000
- Revision:
- 2:249f10554a91
- Parent:
- 1:ff60bc1461ed
- Child:
- 3:70799f249b83
RenBED Counter Seven Segment Display
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jf1452 | 2:249f10554a91 | 1 | /******************************************************************************* |
jf1452 | 2:249f10554a91 | 2 | * This program demonstrates how to drive the seven segment display * |
jf1452 | 2:249f10554a91 | 3 | * * |
jf1452 | 2:249f10554a91 | 4 | * Jon Fuge * |
jf1452 | 2:249f10554a91 | 5 | * V1.0 10/2/2014 First issue of code * |
jf1452 | 2:249f10554a91 | 6 | *******************************************************************************/ |
jf1452 | 2:249f10554a91 | 7 | |
dan | 0:7dec7e9ac085 | 8 | #include "mbed.h" |
jf1452 | 2:249f10554a91 | 9 | #include "SevenSegmentDisplay.h" |
jf1452 | 2:249f10554a91 | 10 | |
jf1452 | 2:249f10554a91 | 11 | // Options to instantiate SevenSegmentDisplay are... |
jf1452 | 2:249f10554a91 | 12 | // FADE: causes the number changes to fade in smoothly |
jf1452 | 2:249f10554a91 | 13 | // INSTANT: causes the an instant number change |
jf1452 | 2:249f10554a91 | 14 | // + FLASH: causes the display to flash |
jf1452 | 2:249f10554a91 | 15 | SevenSegmentDisplay segmentled( FADE ); |
dan | 0:7dec7e9ac085 | 16 | |
jf1452 | 1:ff60bc1461ed | 17 | DigitalOut myled(P0_21); |
dan | 0:7dec7e9ac085 | 18 | |
jf1452 | 2:249f10554a91 | 19 | void Counter(); |
jf1452 | 2:249f10554a91 | 20 | Ticker timeout; //Create an instance of class Ticker called timeout. |
jf1452 | 2:249f10554a91 | 21 | |
dan | 0:7dec7e9ac085 | 22 | int main() { |
jf1452 | 2:249f10554a91 | 23 | timeout.attach(&Counter, 1); |
jf1452 | 2:249f10554a91 | 24 | |
dan | 0:7dec7e9ac085 | 25 | while(1) { |
dan | 0:7dec7e9ac085 | 26 | myled = 1; |
dan | 0:7dec7e9ac085 | 27 | wait(0.2); |
dan | 0:7dec7e9ac085 | 28 | myled = 0; |
dan | 0:7dec7e9ac085 | 29 | wait(0.2); |
dan | 0:7dec7e9ac085 | 30 | } |
dan | 0:7dec7e9ac085 | 31 | } |
jf1452 | 2:249f10554a91 | 32 | |
jf1452 | 2:249f10554a91 | 33 | void Counter() |
jf1452 | 2:249f10554a91 | 34 | { |
jf1452 | 2:249f10554a91 | 35 | static int Count = 0; |
jf1452 | 2:249f10554a91 | 36 | |
jf1452 | 2:249f10554a91 | 37 | segmentled.DisplayInt(Count); |
jf1452 | 2:249f10554a91 | 38 | Count = Count + 1; |
jf1452 | 2:249f10554a91 | 39 | if (Count == 100) |
jf1452 | 2:249f10554a91 | 40 | Count = 0; |
jf1452 | 2:249f10554a91 | 41 | } |