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.
Dependencies: Data_Clock_Pair Seeed_Chainable_LED Seeed_Four_Digit_Disp Seeed_IR_Temp_Sensor Seeed_Led_Bar
Fork of Seeed_Grove_4_Digit_Display_Clock by
Revision 3:c4427ce4d171, committed 2017-04-10
- Comitter:
- tulanthoar
- Date:
- Mon Apr 10 20:40:05 2017 -0600
- Parent:
- 2:1ae739c15893
- Child:
- 4:d540dccad60a
- Commit message:
- change to using 10 led bar on D5/D6
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 10 23:56:10 2017 +0000
+++ b/main.cpp Mon Apr 10 20:40:05 2017 -0600
@@ -1,43 +1,86 @@
#include "mbed.h"
-#include "DigitDisplay.h"
-
-DigitDisplay display(PE_11, PE_9); // 4-Digit Display connected to UART Grove connector
-DigitalOut led(LED1);
-
-Ticker ticker;
-volatile uint8_t second = 0;
-volatile uint8_t minute = 0;
-volatile uint8_t hour = 12;
-volatile bool colon_enable = false;
-void tick()
-{
- colon_enable = !colon_enable;
- display.setColon(colon_enable);
-
- if (colon_enable) {
- second++;
- if (second >= 60) {
- second = 0;
- minute++;
- if (minute >= 60) {
- minute = 0;
- hour++;
- if (hour >= 24) {
- hour = 0;
- }
- }
-
- display.write(hour * 100 + minute);
- }
+Serial pc(SERIAL_TX, SERIAL_RX);
+DigitalOut clk(PE_9);
+DigitalOut dat(PE_11);
+DigitalOut led(LED1);
+
+// Avoid name conflict
+#define LED_GLB_CMDMODE 0x00 // Work on 8-bit mode
+#define LED_GLB_ON 0xff // 8-bit 1 data
+#define LED_GLB_OFF 0x00 // 8-bit 0 data
+
+// Send 16 bits of data
+void sendData(unsigned int data)
+{
+ for (int i = 0; i < 16; i++)
+ {
+ wait_ms(1);
+ unsigned int state = (data & 0x8000) ? 1 : 0;
+ dat = state;
+
+ wait_ms(1);
+ clk = !clk;
+
+ data <<= 1;
+ }
+}
+
+// Send the latch command
+void latchData()
+{
+dat = 0;
+ wait_ms(10);
+
+ for (int i = 0; i < 4; i++)
+ {
+ wait_ms(1);
+ dat=1;
+ wait_ms(1);
+ dat=0;
+ }
+}
+
+// each element in the state will hold the brightness level
+// 00000000 darkest
+// 00000011 brighter
+// ........
+// 11111111 brightest
+void setData(int __state[])
+{
+
+ sendData(LED_GLB_CMDMODE);
+ for (int i = 0; i < 10; i++)
+ {
+ // Go forward on __state
+ sendData(__state[i]);
+ }
+
+ // Two extra empty bits for padding the command to the correct length
+ sendData(0x00);
+ sendData(0x00);
+
+ latchData();
+}
+
+
+
+int main() {
+ pc.printf("\n\nstarting algorithm\n\n");
+ int led_bar[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+ int not_led_bar[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+ setData(led_bar);
+ /* display.setBrightness(7); */
+ /* display.write(100); */
+ /* display.write(5); */
+ /* display.write(hour * 100 + minute);
*/
+ /* ticker.attach(tick, 0.5);
*/
+ while(1) {
+ setData(led_bar);
+ wait(0.5);
+ setData(not_led_bar);
+ pc.printf("iteration\n");
+ led = !led;
+ wait(2);
}
}
-
-int main() {
- display.write(hour * 100 + minute);
- ticker.attach(tick, 0.5);
- while(1) {
- led = !led;
- wait(0.5);
- }
-}
