• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoUse LED light bar on pcDuino
Previous Next

Use LED light bar on pcDuino

Posted by: admin , February 27, 2014

[vc_row][vc_column][vc_column_text][bigcommerce link=”/led-bar-module-of-linker-kit-for-pcduino-arduino/” target=”_blank” rel=”nofollow”]Linker LED bar[/bigcommerce]

The principle of LED light bar is very simple just as the normal digital tube.

Our company’s module use a LED driver chip MY9221 to drive,a number module can be connected together.

My9221 is the LED driver chip which is similar to SPI, it could drive 12 LED lights.

The brightness of each LED light can be achieved by PWM modulation with the data sended by the serial interface .

The following is the picture of the module.

QQ图片20140225215500[/vc_column_text][vc_tour][vc_tab title=”Wiring Diagram” tab_id=”1393480680-1-47″][vc_column_text]QQ图片20140225221337

VCC  – >  pcduino VCC 3.3V

GND  – >  pcduino GND

DCLK  – >  DIN  Dm

DCLK  – >  DIN  Dn (m,n =1, 2, 3…13,the same as the same as the definition in the routine code)[/vc_column_text][/vc_tab][vc_tab title=”Test code” tab_id=”1393480680-2-64″][vc_column_text]

/*
* LED bar test program
*/
#include <core.h>

#define DATA_Pin 4  //DATA IN
#define CLK_Pin  5  //CLK IN
#define LED_pin 2
#define CmdMode 0x0000  //Work on 8-bit mode
#define ON 0x0005               //8-bit 1 data
#define SHUT 0x0000         //8-bit 0 data

void send16bitData(unsigned int data)
{
  unsigned char i;
  boolean clk_pin_state;

  clk_pin_state = digitalRead(CLK_Pin);
  for(i=0;i<16;i++)
  {
      if(data & 0x8000) digitalWrite(DATA_Pin, HIGH);
      else digitalWrite(DATA_Pin, LOW);
      clk_pin_state = !clk_pin_state;
      digitalWrite(CLK_Pin, clk_pin_state); 
      data <<= 1;
      delayMicroseconds(1);
   }
}

//latch routine for MY9221 data exchange
void latchData(void)
{
   unsigned char i;
   boolean data_pin_state;

   digitalWrite(DATA_Pin, LOW);
   data_pin_state = LOW;
   delayMicroseconds(300);
   for(i=0;i<8;i++)
   {
     data_pin_state = !data_pin_state;
     digitalWrite(DATA_Pin, data_pin_state);
     delayMicroseconds(1);
   }
   delayMicroseconds(300);
}

void sendLED(unsigned int LEDstate)
{
  unsigned char i;

  for(i=0;i<12;i++)
  {
    if(LEDstate&0x0001)send16bitData(ON);
    else  send16bitData(SHUT);
    LEDstate >>= 1;
  }
}

void setup()
{
    pinMode(DATA_Pin,OUTPUT);   //Data pin
    pinMode(CLK_Pin,OUTPUT);  //CLK pin
    pinMode(LED_pin,OUTPUT);  //LED_pin
    digitalWrite(DATA_Pin, LOW);
    digitalWrite(CLK_Pin, LOW);
}

void loop()
{
  unsigned int tmpInt;

  for(tmpInt=1;tmpInt < 0xFFF;tmpInt |= (tmpInt<<1))
  {
    send16bitData(CmdMode); //set LED Bar mode
    sendLED(tmpInt);        //send LED Bar data
    latchData();  //make it come into effect
    delay(100);
  }
  digitalWrite(LED_pin, LOW);
  for(;tmpInt != 0;tmpInt >>=1)
  {
    send16bitData(CmdMode); //set LED Bar mode
    sendLED(tmpInt);        //send LED Bar data
    latchData();  //make it come into effect
    delay(100);
  }
  send16bitData(CmdMode); //set LED Bar mode
  sendLED(0);        //send LED Bar data
  latchData();  //make it come into effect
  delay(100);
  digitalWrite(LED_pin, HIGH);

}
I am text block. Click edit button to change this text.

[/vc_column_text][/vc_tab][vc_tab title=”Test result” tab_id=”1393538983776-2-5″][vc_column_text]

QQ图片20140225215413
QQ图片20140225223041

[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: pcDuino

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors