Sally Brown / Mbed 2 deprecated RenBed_Tutorial3

Dependencies:   SevenSegLed mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*******************************************************************************
00002 * This program demonstrates how to drive the seven segment display *
00003 * *
00004 * Jon Fuge *
00005 * V1.0 13/12/2013 First issue of code *
00006 *******************************************************************************/
00007 #include "mbed.h"
00008 #include "SevenSegLed.h"
00009 
00010 // Lets define some "macros" to make the code easier to read
00011 #define mUnits D_7seg[1]    // "mUnits" will be substiuted for "D_7seg[1]"
00012 #define mTens D_7seg[0]     // "mTens" will be substiuted for "D_7seg[0]"
00013 #define mDot D_dot[1]       // "mDot" will be substiuted for "D_dot[1]"
00014 
00015 void attimeout(); //declare prototype for timeout handler.
00016 //configure sevensegled pin connection mapping.
00017 //
00018 // common type (0:anode common 1:cathode common)
00019 // | display mode (0:smooth 1:hard)
00020 // | | segA segB segC segD segE segF segG segP com1 com2
00021 SevenSegLed segmentled(0, 0, P1_23, P1_28, P0_16, P1_31, P1_13, P1_16, P1_19, P0_23, p21, P1_25);
00022 
00023 //Define two arrays to house the data to be outputted. D_7seg can contain digits 0‐F and D_dot 0‐1.
00024 //
00025 // 0 1 //0 = leftmost digit, 1 = rightmost digit
00026 // | |
00027 uint8_t D_7seg[2] = {0, 0}; // number (0x00:"0", ... , 0x09:"9", 0x0A:"A", ... , 0x0F:"F", other:" ")
00028 uint8_t D_dot[2] = {0, 0}; // dotpoint. (0:off 1:on)
00029 Ticker timeout; //Create an instance of class Ticker called timeout.
00030 
00031 int main()
00032 {
00033     timeout.attach_us(&attimeout, 500000); // Set up interrupt to call attimeout() every half a second.
00034     for(;;)
00035     {
00036         segmentled.SevenSegLed_main(D_7seg, D_dot); // Keep the displays multiplexed.
00037     }
00038 }
00039 
00040 void attimeout() //Timer interrupt routine.
00041 {
00042     mDot = 1 - mDot;
00043     if (mDot == 1) 
00044     {
00045         mUnits++; // This means the same as D_7seg[0] = D_7seg[0] + 1; Increment "units"
00046         
00047         if (mUnits > 9)
00048         { // "units" digit should be in the range 0 ‐> 9
00049             mUnits = 0; // Reset the "units" to 0
00050             mTens++; // Increment "tens" digit
00051             
00052             if (mTens > 9)
00053             { // "tens" digit should be in the range 0 ‐> 9
00054                 mTens = 0; // Reset the "tens" to 0
00055             }
00056         }
00057     }
00058 }