Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: SensorExamples-mDS-Ethernet SensorNotifyLED SensorNotifyLED Seeed_Grove_Shield_LED_Bar ... more
Revision 0:edcb13b58b4f, committed 2014-07-30
- Comitter:
- screamer
- Date:
- Wed Jul 30 10:27:21 2014 +0000
- Commit message:
- Initial revision
Changed in this revision
| LED_Bar.cpp | Show annotated file Show diff for this revision Revisions of this file |
| LED_Bar.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r edcb13b58b4f LED_Bar.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LED_Bar.cpp Wed Jul 30 10:27:21 2014 +0000
@@ -0,0 +1,93 @@
+/*
+LED bar library V1.0
+2010 Copyright (c) Seeed Technology Inc. All right reserved.
+
+Original Author: LG
+
+Modify: Mihail Stoyanov (mihail.stoyanov@arm.com) for ARM mbed, 2014-07-30
+User can choose which Io to be used.
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "LED_Bar.h"
+
+LED_Bar::LED_Bar(PinName pinClk, PinName pinDta) : __pinClk(pinClk), __pinDta(pinDta)
+{
+ __led_state = 0x00;
+}
+
+void LED_Bar::latchData()
+{
+ __pinDta = 0;
+ wait_us(10);
+
+ for(int i=0; i<4; i++) {
+ __pinDta = 1;
+ __pinDta = 0;
+ }
+
+}
+
+void LED_Bar::send16bitData(unsigned int data)
+{
+ for(int i=0; i<16; i++) {
+ unsigned int state = data & 0x8000 ? 1 : 0;
+ __pinDta = state;
+
+ state = __pinClk ? 0 : 1;
+ __pinClk = state;
+
+ data <<= 1;
+ }
+}
+
+void LED_Bar::ledIndexBit(unsigned int index_bits)
+{
+
+ send16bitData(CMDMODE);
+
+ for (int i=0; i<12; i++) {
+ unsigned int state = (index_bits&0x0001) ? ON : SHUT;
+ send16bitData(state);
+
+ index_bits = index_bits>>1;
+ }
+
+ latchData();
+}
+
+void LED_Bar::setLevel(int level)
+{
+
+ if(level>10)return;
+
+ send16bitData(CMDMODE);
+
+ for(int i=0; i<12; i++) {
+ unsigned int state1 = (i<level) ? ON : SHUT;
+
+ send16bitData(state1);
+ }
+
+ latchData();
+}
+
+void LED_Bar::setSingleLed(int num, int st)
+{
+ if(num>10)return;
+ __led_state = st ? (__led_state | (0x01<<num)) : (__led_state & ~(0x01<<num));
+ ledIndexBit(__led_state);
+
+}
diff -r 000000000000 -r edcb13b58b4f LED_Bar.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LED_Bar.h Wed Jul 30 10:27:21 2014 +0000
@@ -0,0 +1,82 @@
+/*
+LED bar library V1.0
+2010 Copyright (c) Seeed Technology Inc. All right reserved.
+
+Original Author: LG
+Modify: Loovee, 2014-2-26
+User can choose which Io to be used.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "mbed.h"
+
+#ifndef LED_Bar_H
+#define LED_Bar_H
+
+#define CMDMODE 0x0000 // Work on 8-bit mode
+#define ON 0x00ff // 8-bit 1 data
+#define SHUT 0x0000 // 8-bit 0 data
+
+/**
+ * The LED_Bar interface
+ */
+class LED_Bar
+{
+
+public:
+ LED_Bar(PinName pinClk, PinName pinDta);
+
+ /**
+ * Set led single bit, a bit contrl a led
+ * @param index_bits which bit. if 0x05, then led 0 and led 3 will on, the others will off
+ */
+ void ledIndexBit(unsigned int index_bits);
+
+ /**
+ * Set level, frm 0 to 10.
+ * @param level Level 0 means all leds off while level 5 means 5led on and the other will off
+ */
+ void setLevel(int level);
+
+ /**
+ * Control a single led
+ * @param num which led
+ * @param st 1: on 0: off
+ */
+ void setSingleLed(int num, int st);
+
+private:
+ /**
+ * Pin for clock
+ */
+ DigitalOut __pinClk;
+
+ /**
+ * Pin for data
+ */
+ DigitalOut __pinDta;
+
+ /**
+ * LED State
+ */
+ unsigned int __led_state;
+
+ void send16bitData(unsigned int data);
+ void latchData(void);
+
+};
+
+#endif
\ No newline at end of file
Grove Seeed LED Bar