A stripped down simple seven segement example for RedBED

Dependencies:   mbed

Committer:
JimCordwell
Date:
Sat May 24 11:33:36 2014 +0000
Revision:
3:6b50a41e54f3
Parent:
2:91808e29f193
Child:
4:84ce87a4a8e8
Fixed a bug that was causing a duplicated image on the left LED

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JimCordwell 0:308c4a8d774b 1 /**************************************************************************
JimCordwell 0:308c4a8d774b 2 * *
JimCordwell 0:308c4a8d774b 3 * A stripped down simple seven segement example for RedBED *
JimCordwell 0:308c4a8d774b 4 * *
JimCordwell 0:308c4a8d774b 5 * The LED block actually has 8 illuminable sections *
JimCordwell 0:308c4a8d774b 6 * segments 'a' to 'g' for the main display and 'p' for a decimal point *
JimCordwell 0:308c4a8d774b 7 * _________ *
JimCordwell 0:308c4a8d774b 8 * <____a____> *
JimCordwell 0:308c4a8d774b 9 * / \ / \ *
JimCordwell 0:308c4a8d774b 10 * | | | | *
JimCordwell 0:308c4a8d774b 11 * |f| |b| *
JimCordwell 0:308c4a8d774b 12 * | | | | *
JimCordwell 0:308c4a8d774b 13 * \ /_________ \ / *
JimCordwell 0:308c4a8d774b 14 * <____g____> *
JimCordwell 0:308c4a8d774b 15 * / \ / \ *
JimCordwell 0:308c4a8d774b 16 * | | | | *
JimCordwell 0:308c4a8d774b 17 * |e| |c| *
JimCordwell 0:308c4a8d774b 18 * | | | | *
JimCordwell 0:308c4a8d774b 19 * \ /_________ \ / *
JimCordwell 0:308c4a8d774b 20 * <____d____> |p| *
JimCordwell 0:308c4a8d774b 21 * *
JimCordwell 0:308c4a8d774b 22 **************************************************************************/
JimCordwell 0:308c4a8d774b 23
JimCordwell 0:308c4a8d774b 24 #include "mbed.h"
JimCordwell 0:308c4a8d774b 25
JimCordwell 0:308c4a8d774b 26 uint8_t left = 0;
JimCordwell 0:308c4a8d774b 27 uint8_t right = 1;
JimCordwell 0:308c4a8d774b 28
JimCordwell 0:308c4a8d774b 29 //The 8 segment outputs and com to switch between the LEDs
JimCordwell 0:308c4a8d774b 30 DigitalOut seg_a(P1_23), seg_b(P1_28), seg_c(P0_16), seg_d(P1_31), seg_e(P1_13), seg_f(P1_16), seg_g(P1_19), seg_p(P0_23), com(P1_25);
JimCordwell 0:308c4a8d774b 31
JimCordwell 0:308c4a8d774b 32 /******************************************************
JimCordwell 2:91808e29f193 33 * Set each of the segments for a desired LED *
JimCordwell 0:308c4a8d774b 34 ******************************************************/
JimCordwell 0:308c4a8d774b 35 void SetSegments(uint8_t led, uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f, uint8_t g, uint8_t p)
JimCordwell 0:308c4a8d774b 36 {
JimCordwell 1:1336ea4dd725 37 //Set left LED
JimCordwell 1:1336ea4dd725 38 com = left;
JimCordwell 0:308c4a8d774b 39
JimCordwell 0:308c4a8d774b 40 //Switch off all segments (1 means off!)
JimCordwell 0:308c4a8d774b 41 seg_a = seg_b = seg_c = seg_d = seg_e = seg_f = seg_g = seg_p = 1;
JimCordwell 0:308c4a8d774b 42
JimCordwell 1:1336ea4dd725 43 //Set desired LED to update
JimCordwell 1:1336ea4dd725 44 com = led;
JimCordwell 0:308c4a8d774b 45
JimCordwell 3:6b50a41e54f3 46 //Update it in a loop to the desired values
JimCordwell 0:308c4a8d774b 47 for(uint8_t i = 0; i < 100; i++)
JimCordwell 0:308c4a8d774b 48 {
JimCordwell 1:1336ea4dd725 49 seg_a = 1 - a; //setting a segment to 1 means off
JimCordwell 1:1336ea4dd725 50 seg_b = 1 - b; //so invert all requested segment values
JimCordwell 0:308c4a8d774b 51 seg_c = 1 - c;
JimCordwell 0:308c4a8d774b 52 seg_d = 1 - d;
JimCordwell 0:308c4a8d774b 53 seg_e = 1 - e;
JimCordwell 0:308c4a8d774b 54 seg_f = 1 - f;
JimCordwell 0:308c4a8d774b 55 seg_g = 1 - g;
JimCordwell 0:308c4a8d774b 56 seg_p = 1 - p;
JimCordwell 0:308c4a8d774b 57 }
JimCordwell 3:6b50a41e54f3 58
JimCordwell 3:6b50a41e54f3 59 //Finally switch off all segments again, we must do this otherwise when
JimCordwell 3:6b50a41e54f3 60 //switching com the segments will momentarily duplicated from this led.
JimCordwell 3:6b50a41e54f3 61 seg_a = seg_b = seg_c = seg_d = seg_e = seg_f = seg_g = seg_p = 1;
JimCordwell 0:308c4a8d774b 62 }
JimCordwell 0:308c4a8d774b 63
JimCordwell 0:308c4a8d774b 64 /******************************************************
JimCordwell 0:308c4a8d774b 65 * Main loop repeatedly updates each of the LEDs *
JimCordwell 0:308c4a8d774b 66 ******************************************************/
JimCordwell 0:308c4a8d774b 67 int main()
JimCordwell 0:308c4a8d774b 68 {
JimCordwell 0:308c4a8d774b 69 for(;;)
JimCordwell 0:308c4a8d774b 70 {
JimCordwell 3:6b50a41e54f3 71 //Set the display to read '42'
JimCordwell 0:308c4a8d774b 72 SetSegments(left, 0,1,1,0,0,1,1,0); //4
JimCordwell 0:308c4a8d774b 73 SetSegments(right, 1,1,0,1,1,0,1,0); //2
JimCordwell 0:308c4a8d774b 74 }
JimCordwell 0:308c4a8d774b 75 }
JimCordwell 0:308c4a8d774b 76