Very simple library for controll a 7 segment display.
Dependents: Demo_Led7seg TP1_EJER02_FERNANDEZ_CLERICI TP1_EJER3 Ejercicio3JalleVentiades ... more
Revision 1:78b3b8aefd3c, committed 2011-04-23
- Comitter:
- trombettamichele
- Date:
- Sat Apr 23 10:30:59 2011 +0000
- Parent:
- 0:ccabe7ff24e8
- Commit message:
Changed in this revision
diff -r ccabe7ff24e8 -r 78b3b8aefd3c Led7Seg.h --- a/Led7Seg.h Fri Apr 22 22:30:33 2011 +0000 +++ b/Led7Seg.h Sat Apr 23 10:30:59 2011 +0000 @@ -1,22 +1,31 @@ #include "mbed.h" -#define led_ANODE 0 -#define led_CATHODE 1 // Simple library that can controll a 7 segment led display // Created by Michele Trombetta // Copyright 2010 5OFT. All rights reserved. +#ifndef led_ANODE +#define led_ANODE 0 +#define led_CATHODE 1 +#endif + +#ifndef VAR_num_7seg +#define VAR_num_7seg //Chars: 0123456789AbCdEF const unsigned char num_7seg[24] = {0x3F, 0x6, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x7, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00}; +#endif +#ifndef LIB_Led7Seg +#define LIB_Led7Seg class Led7Seg { public: Led7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g); Led7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g, bool led_type); - void set_type(bool led_type); - void write(unsigned char number); - unsigned char read(); - unsigned char convert(unsigned char number); + void set_type(bool led_type); // Set the tyep of the display (Anode or Cathode comm.) + void write(unsigned char number); // Write the data to the display + unsigned char read(); // Read the data of the display + unsigned char convert(unsigned char number); // Only convert the data, no visualization private: BusOut _leddisp; bool _led_type; -}; \ No newline at end of file +}; +#endif \ No newline at end of file
diff -r ccabe7ff24e8 -r 78b3b8aefd3c Multi7Seg.cpp --- a/Multi7Seg.cpp Fri Apr 22 22:30:33 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +0,0 @@ -#include "mbed.h" -#include "Multi7Seg.h" -// Simple library that can controll a matrix of 7 segment led displays -// Created by Michele Trombetta -// Copyright 2010 5OFT. All rights reserved. - -Multi7Seg::Multi7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g, PinName disp1, PinName disp2, bool led_type): _disps(disp1, disp2), _led_7seg(a, b, c, d, e, f, g, led_type) { - _ndisp = 2; - _speed = 0.001; -} - -Multi7Seg::Multi7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g, PinName disp1, PinName disp2, PinName disp3, bool led_type): _disps(disp1, disp2, disp3), _led_7seg(a, b, c, d, e, f, g, led_type) { - _ndisp = 3; - _speed = 0.001; -} - -Multi7Seg::Multi7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g, PinName disp1, PinName disp2, PinName disp3, PinName disp4, bool led_type): _disps(disp1, disp2, disp3, disp4), _led_7seg(a, b, c, d, e, f, g, led_type) { - _ndisp = 4; - _speed = 0.001; -} - -Multi7Seg::Multi7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g, PinName disp1, PinName disp2, PinName disp3, PinName disp4, PinName disp5, bool led_type): _disps(disp1, disp2, disp3, disp4, disp5), _led_7seg(a, b, c, d, e, f, g, led_type) { - _ndisp = 5; - _speed = 0.001; -} - -void Multi7Seg::write(unsigned int number) { - if (_format) { //Dec - _num1 = number / 10000; - _num2 = (number % 10000)/1000; - _num3 = (number % 1000)/100; - _num4 = (number % 100)/10; - _num5 = number % 10; - } else { //Hex - _num2 = (number % 65536)/4096; - _num3 = (number % 4096)/256; - _num4 = (number % 256)/16; - _num5 = number % 16; - } - - switch (_ndisp) { - case 5: - _disps = 0; - _led_7seg.write((unsigned char)_num1); - _disps = 16; - wait(_speed); - case 4: - _disps = 0; - _led_7seg.write((unsigned char)_num2); - _disps = 8; - wait(_speed); - case 3: - _disps = 0; - _led_7seg.write((unsigned char)_num3); - _disps = 4; - wait(_speed); - case 2: - _disps = 0; - _led_7seg.write((unsigned char)_num4); - _disps = 2; - wait(_speed); - - _disps = 0; - _led_7seg.write((unsigned char)_num5); - _disps = 1; - wait(_speed); - } - _disps = 0; -} - -void Multi7Seg::setformat(bool format) { - _format = format; -} - -void Multi7Seg::setspeed(float speed) { - _speed = speed; -} \ No newline at end of file
diff -r ccabe7ff24e8 -r 78b3b8aefd3c Multi7Seg.h --- a/Multi7Seg.h Fri Apr 22 22:30:33 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -#include "mbed.h" -#include "Led7Seg.h" - -#define format_DEC 0 -#define format_HEX 1 -// Simple library that can controll a matrix of 7 segment led displays -// Created by Michele Trombetta -// Copyright 2010 5OFT. All rights reserved. - -class Multi7Seg { -public: - Multi7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g, PinName disp1, PinName disp2, bool led_type); - Multi7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g, PinName disp1, PinName disp2, PinName disp3, bool led_type); - Multi7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g, PinName disp1, PinName disp2, PinName disp3, PinName disp4, bool led_type); - Multi7Seg(PinName a, PinName b, PinName c, PinName d, PinName e, PinName f, PinName g, PinName disp1, PinName disp2, PinName disp3, PinName disp4, PinName disp5, bool led_type); - void write(unsigned int number); // Write the number to the led displays - void setformat(bool format); // Set the format (0-Dec 1-Hex) - void setspeed(float speed); // Set the delay time for digits scanning - -private: - BusOut _disps; - Led7Seg _led_7seg; - unsigned char _ndisp; - bool _format; - float _speed; - unsigned int _num1, _num2, _num3, _num4, _num5; -}; \ No newline at end of file
diff -r ccabe7ff24e8 -r 78b3b8aefd3c main.cpp --- a/main.cpp Fri Apr 22 22:30:33 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -#include "mbed.h" -#include "Multi7Seg.h" -//##### A simple Clock ##### -// Created by Michele Trombetta -// Copyright 2010 5OFT. All rights reserved. - -Ticker ticker_sec; -Multi7Seg minutes(p21, p22, p23, p24, p25, p26, p27, p20, p19, led_ANODE); -Multi7Seg hours(p21, p22, p23, p24, p25, p26, p27, p18, p17, led_ANODE); -DigitalOut seconds(p16); - -unsigned int cnt_h = 0, cnt_m = 0, cnt_s = 0; - -void inc_num() { - cnt_s++; - seconds = !seconds; - if (cnt_s == 60) { - cnt_s = 0; - cnt_m++; - } - if (cnt_m == 60) { - cnt_m = 0; - cnt_h++; - } - if (cnt_h == 24) cnt_h = 0; -} - -int main() { - - ticker_sec.attach(&inc_num, 1); - seconds = 0; - hours.setformat(format_DEC); - minutes.setformat(format_DEC); - - while (1) { - hours.write(cnt_h); - minutes.write(cnt_m); - } -} \ No newline at end of file
diff -r ccabe7ff24e8 -r 78b3b8aefd3c mbed.bld --- a/mbed.bld Fri Apr 22 22:30:33 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912