The example program for RenBED to deomonstrate ticker and the Seven Segment Display Driver

Dependencies:   SevenSegmentDisplay mbed

Fork of RenBEDCounter by Jon Fuge

Committer:
jf1452
Date:
Thu May 08 13:36:13 2014 +0000
Revision:
4:47649aacd984
Parent:
3:70799f249b83
Update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jf1452 2:249f10554a91 1 /*******************************************************************************
jf1452 3:70799f249b83 2 * Used to drive RenBed with a reaction timer game *
jf1452 3:70799f249b83 3 * Copyright (c) 2014 Renishaw plc *
jf1452 3:70799f249b83 4 * *
jf1452 3:70799f249b83 5 * Permission is hereby granted, free of charge, to any person obtaining a copy *
jf1452 3:70799f249b83 6 * of this software and associated documentation files (the "Software"), to deal*
jf1452 3:70799f249b83 7 * in the Software without restriction, including without limitation the rights *
jf1452 3:70799f249b83 8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
jf1452 3:70799f249b83 9 * copies of the Software, and to permit persons to whom the Software is *
jf1452 3:70799f249b83 10 * furnished to do so, subject to the following conditions: *
jf1452 2:249f10554a91 11 * *
jf1452 3:70799f249b83 12 * The above copyright notice and this permission notice shall be included in *
jf1452 3:70799f249b83 13 * all copies or substantial portions of the Software. *
jf1452 3:70799f249b83 14 * *
jf1452 3:70799f249b83 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
jf1452 3:70799f249b83 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
jf1452 3:70799f249b83 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
jf1452 3:70799f249b83 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
jf1452 3:70799f249b83 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,*
jf1452 3:70799f249b83 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
jf1452 3:70799f249b83 21 * THE SOFTWARE. *
jf1452 3:70799f249b83 22 * *
jf1452 3:70799f249b83 23 * RenBed_Reaction_Timer *
jf1452 3:70799f249b83 24 * *
jf1452 3:70799f249b83 25 * V1.0 8/5/2014 Jon Fuge *
jf1452 2:249f10554a91 26 *******************************************************************************/
jf1452 2:249f10554a91 27
dan 0:7dec7e9ac085 28 #include "mbed.h"
jf1452 2:249f10554a91 29 #include "SevenSegmentDisplay.h"
jf1452 2:249f10554a91 30
jf1452 3:70799f249b83 31 SevenSegmentDisplay segmentled( FADE ); // Configure display to fade numbers in
dan 0:7dec7e9ac085 32
jf1452 3:70799f249b83 33 DigitalOut myled(P1_14); // Define an output pin for the LED
jf1452 3:70799f249b83 34 DigitalIn mybutton(P0_9); // We use DebounceIn for mechanical switches
dan 0:7dec7e9ac085 35
jf1452 3:70799f249b83 36 void Counter(); // Define our counter function
jf1452 2:249f10554a91 37 Ticker timeout; //Create an instance of class Ticker called timeout.
jf1452 2:249f10554a91 38
jf1452 3:70799f249b83 39 int iCount; // Variable to store counter
jf1452 3:70799f249b83 40
dan 0:7dec7e9ac085 41 int main() {
jf1452 3:70799f249b83 42
jf1452 4:47649aacd984 43 mybutton.mode(PullUp); // Set switch input to pull-up mode
jf1452 4:47649aacd984 44 segmentled.DisplayDigits(36,36); // Turn display off
jf1452 2:249f10554a91 45
jf1452 4:47649aacd984 46 while (mybutton == 0) {} // Wait for button change
jf1452 4:47649aacd984 47 wait(5); // wait for five seconds before starting game
jf1452 4:47649aacd984 48 myled = 1; // Turn the LED on
jf1452 4:47649aacd984 49 segmentled.DisplayDigits(16,24); // Display Go
jf1452 4:47649aacd984 50 timeout.attach_us(&Counter, 10000); // Set up a 10ms counter for Hundreths of a second
jf1452 3:70799f249b83 51
jf1452 3:70799f249b83 52 while ((mybutton == 1) && (iCount <99)) {} // Wait for button change
jf1452 3:70799f249b83 53
jf1452 4:47649aacd984 54 timeout.detach(); // Stop the timer
jf1452 3:70799f249b83 55
jf1452 4:47649aacd984 56 segmentled.DisplayInt(iCount); // Display reaction time.
jf1452 4:47649aacd984 57 myled = 0; // Turn the LED off
jf1452 3:70799f249b83 58 while (1) {};
dan 0:7dec7e9ac085 59 }
jf1452 2:249f10554a91 60
jf1452 2:249f10554a91 61 void Counter()
jf1452 2:249f10554a91 62 {
jf1452 4:47649aacd984 63 iCount = iCount + 1; // Count hundreths of a second
jf1452 2:249f10554a91 64 }