Simple 6-LED bar library. Provides some useful functions.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers 6LedBar.cpp Source File

6LedBar.cpp

00001 #include "6LedBar.h"
00002 
00003 LedBar::LedBar(PinName p0, PinName p1, PinName p2,
00004                PinName p3, PinName p4, PinName p5) :
00005             l0(p0), l1(p1), l2(p2), l3(p3), l4(p4), l5(p5)
00006 {
00007     m_leds[0] = &l0;
00008     m_leds[1] = &l1;
00009     m_leds[2] = &l2;
00010     m_leds[3] = &l3;
00011     m_leds[4] = &l4;
00012     m_leds[5] = &l5;
00013 
00014 }
00015 
00016 void LedBar::on(int n) {
00017     if(n < LEDS_COUNT) {
00018         *(m_leds[n]) = 1;
00019     }
00020 }
00021 
00022 void LedBar::off(int n) {
00023     if(n < LEDS_COUNT) {
00024         *(m_leds[n]) = 0;
00025     }
00026 }
00027 
00028 void LedBar::toggle(int n) {
00029     if(n < LEDS_COUNT) {
00030         *(m_leds[n]) = ! (*m_leds[n]);
00031     }
00032 }
00033 
00034 void LedBar::on_mask(int m) {
00035     for(int i = 0; i < LEDS_COUNT; i++) {
00036         if(m & (1 << i)) {
00037             on(i);
00038         }
00039     }
00040 }
00041 
00042 void LedBar::off_mask(int m) {
00043     for(int i = 0; i < LEDS_COUNT; i++) {
00044         if(m & (1 << i)) {
00045             off(i);
00046         }
00047     }
00048 }
00049 
00050 void LedBar::toggle_mask(int m) {
00051     for(int i = 0; i < LEDS_COUNT; i++) {
00052         if(m & (1 << i)) {
00053             toggle(i);
00054         }
00055     }
00056 }
00057 
00058 void LedBar::set_mask(int m) {
00059     for(int i = 0; i < LEDS_COUNT; i++) {
00060         if(m & (1 << i)) {
00061             on(i);
00062         }
00063         else {
00064             off(i);
00065         }
00066     }
00067 }