Linker Kit 所有的示例代码可以在 这里下载。
这里需要用到的代码如下:
- /*
- * LED bar test program for a10
- */
- #include
- #define DATA_Pin 0 //DATA IN
- #define CLK_Pin 1 //CLK IN
- #define CmdMode 0x0000 //Work on 8-bit mode
- #define ON 0x00ff //8-bit 1 data
- #define SHUT 0x0000 //8-bit 0 data
- static int s_clk_flag = 0;
- void send16bitData(unsigned int data)
- {
- for(unsigned char i=0;i<16;i++){
- if(data & 0x8000){
- digitalWrite(DATA_Pin, HIGH);
- }else{
- digitalWrite(DATA_Pin, LOW);
- }
- if(s_clk_flag){
- digitalWrite(CLK_Pin, LOW);
- s_clk_flag = 0;
- }else{
- digitalWrite(CLK_Pin, HIGH);
- s_clk_flag = 1;
- }
- data <<= 1;
- }
- }
- //latch routine for MY9221 data exchange
- void latchData(void)
- {
- int latch_flag = 0;
- digitalWrite(DATA_Pin, LOW);
- delayMicroseconds(200);
- for(unsigned char i=0;i<8;i++){
- if(latch_flag){
- digitalWrite(DATA_Pin, LOW);
- latch_flag = 0;
- }else{
- digitalWrite(DATA_Pin, HIGH);
- latch_flag = 1;
- }
- }
- delayMicroseconds(200);
- }
- void sendLED(unsigned int LEDstate)
- {
- unsigned char i;
- for(i=0;i<12;i++) { if(LEDstate&0x0001) send16bitData(ON); else send16bitData(SHUT); LEDstate=LEDstate>>1;
- }
- }
- void setup()
- {
- printf("LED bar test code!\n");
- printf("Using I/O_0=DATA, I/O_1=CLK.\n");
- pinMode(DATA_Pin,OUTPUT); //Data pin
- pinMode(CLK_Pin,OUTPUT); //CLK pin
- digitalWrite(DATA_Pin, LOW);
- digitalWrite(CLK_Pin, LOW);
- s_clk_flag = 0;
- }
- void loop()
- {
- /*
- send16bitData(CmdMode); //set LED Bar mode
- sendLED(0x0155); //send LED Bar data
- latchData(); //make it come into effect
- delay(2000);
- send16bitData(CmdMode); //set LED Bar mode
- sendLED(0x02aa); //send LED Bar data
- latchData(); //make it come into effect
- delay(2000);
- */
- unsigned int i = 0x0000;
- unsigned int loop = 0x0;
- while(i<=0x03ff)
- {
- send16bitData(CmdMode); //set LED Bar mode
- sendLED(i); //send LED Bar data
- latchData(); //make it come into effect
- i=i*2+1;
- delay(100);
- }
- }
复制代码在编译之前还需要修改位于“myworkingdirectory/arduino/sample”路径的“Makefile”。
- DIR=$(shell pwd)/../
- INCS = -I.\
- -I$(DIR) \
- -I$(DIR)/hardware \
- -I$(DIR)/hardware/arduino \
- -I$(DIR)/hardware/arduino/cores \
- -I$(DIR)/hardware/arduino/cores/arduino \
- -I$(DIR)/hardware/arduino/variants \
- -I$(DIR)/hardware/arduino/variants/sunxi \
- -I$(DIR)/libraries \
- -I$(DIR)/libraries/Serial \
- -I$(DIR)/libraries/SPI \
- -I$(DIR)/libraries/Wire \
- -I$(DIR)/libraries/LiquidCrystal \
- -I$(DIR)/libraries/ADXL345 \
- -I$(DIR)/libraries/TFTtouch
- LIBS=../libarduino.a
- TARGET=../output/test
- OBJS = paint Motor_shield xbee_relay xbee_shield relay_shield nfc_test drawCircle test sim900 smg \
- io_test adc_test pwm_test spi_test adxl345_test serial_test liquidcrystal_i2c liquidcrystal_spi \
- linker_led_bar_test
- all:
- @mkdir -p $(TARGET)
- for i in $(OBJS); do echo "$(CXX) $(INCS) $$i.c -o $(TARGET)/$$i $(LIBS)"; done
- @for i in $(OBJS); do $(CXX) $(INCS) $$i.c -o $(TARGET)/$$i $(LIBS); done
- clean:
- @for i in $(OBJS); do rm -f $(TARGET)/$$i; done
复制代码接着需要添加 “linker_led_bar_test”路径到 OBJS。 找到 “sample”目录,输入“make”进行编译。 然后连接Linker LED bar,引脚连接方法: l GND of LED bar -> GND of pcDuino l VCC of LED bar -> 3.3V of pcDuino l DCKI of LED bar ->D1 of pcDuino(TX) l DI of LED bar -> D0 of pcDuino(RX)
|