Jim Cordwell
/
Segments_01_Simple
A stripped down simple seven segement example for RedBED
main.cpp
- Committer:
- JimCordwell
- Date:
- 2014-05-24
- Revision:
- 2:91808e29f193
- Parent:
- 1:1336ea4dd725
- Child:
- 3:6b50a41e54f3
File content as of revision 2:91808e29f193:
/************************************************************************** * * * A stripped down simple seven segement example for RedBED * * * * The LED block actually has 8 illuminable sections * * segments 'a' to 'g' for the main display and 'p' for a decimal point * * _________ * * <____a____> * * / \ / \ * * | | | | * * |f| |b| * * | | | | * * \ /_________ \ / * * <____g____> * * / \ / \ * * | | | | * * |e| |c| * * | | | | * * \ /_________ \ / * * <____d____> |p| * * * **************************************************************************/ #include "mbed.h" uint8_t left = 0; uint8_t right = 1; //The 8 segment outputs and com to switch between the LEDs 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); /****************************************************** * Set each of the segments for a desired LED * ******************************************************/ 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) { //Set left LED com = left; //Switch off all segments (1 means off!) seg_a = seg_b = seg_c = seg_d = seg_e = seg_f = seg_g = seg_p = 1; //Set desired LED to update com = led; //Update it in a loop otherwise it's too fast //and the display blurs across the LEDs for(uint8_t i = 0; i < 100; i++) { seg_a = 1 - a; //setting a segment to 1 means off seg_b = 1 - b; //so invert all requested segment values seg_c = 1 - c; seg_d = 1 - d; seg_e = 1 - e; seg_f = 1 - f; seg_g = 1 - g; seg_p = 1 - p; } } /****************************************************** * Main loop repeatedly updates each of the LEDs * ******************************************************/ int main() { for(;;) { SetSegments(left, 0,1,1,0,0,1,1,0); //4 SetSegments(right, 1,1,0,1,1,0,1,0); //2 } }