fork of seeed studio 4-digit display for st nucleo board
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
main.cpp
- Committer:
- tulanthoar
- Date:
- 2017-04-10
- Revision:
- 3:c4427ce4d171
- Parent:
- 2:1ae739c15893
- Child:
- 4:d540dccad60a
File content as of revision 3:c4427ce4d171:
#include "mbed.h" 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); } }