0
ufo

我用  ameba 要來控制 grove led strip driver的燈條。

程式庫 在這個網頁http://wiki.seeed.cc/Grove-LED_Strip_Driver/

安裝完,執行的結果,紅色和綠色出的來。藍色就不會亮

但如果用arduino 來跑,就一切正常。不知是什麼原因

煩請幫我解惑,謝謝

他的函式庫如下

#include "RGBdriver.h"

RGBdriver::RGBdriver(uint8_t Clk, uint8_t Data)
{
Clkpin = Clk;
Datapin = Data;
pinMode(Datapin, OUTPUT);
pinMode(Clkpin, OUTPUT);
}

void RGBdriver::begin(void)
{
Send32Zero();
}

void RGBdriver::end(void)
{
Send32Zero();
}

void RGBdriver::ClkRise(void)
{

digitalWrite(Clkpin, LOW);
delayMicroseconds(20);
digitalWrite(Clkpin, HIGH);
delayMicroseconds(20);

}

void RGBdriver::Send32Zero(void)
{
unsigned char i;

for (i=0; i<32; i++)
{
digitalWrite(Datapin, LOW);
ClkRise();
}
}

uint8_t RGBdriver::TakeAntiCode(uint8_t dat)
{
uint8_t tmp = 0;

if ((dat & 0x80) == 0)
{
tmp |= 0x02;
}

if ((dat & 0x40) == 0)
{
tmp |= 0x01;
}

return tmp;
}

// gray data
void RGBdriver::DatSend(uint32_t dx)
{
uint8_t i;

for (i=0; i<32; i++)
{
if ((dx & 0x80000000) != 0)
{
digitalWrite(Datapin, HIGH);
}
else
{
digitalWrite(Datapin, LOW);
}

dx <<= 1;
ClkRise();
}

}

// Set color
void RGBdriver::SetColor(uint8_t Red,uint8_t Green,uint8_t Blue)
{
uint32_t dx = 0;

dx |= (uint32_t)0x03 << 30; // highest two bits 1,flag bits
dx |= (uint32_t)TakeAntiCode(Blue) << 28;
dx |= (uint32_t)TakeAntiCode(Green) << 26;
dx |= (uint32_t)TakeAntiCode(Red) << 24;

dx |= (uint32_t)Blue << 16;
dx |= (uint32_t)Green << 8;
dx |= Red;
DatSend(dx);
}

程式碼如下

#include "RGBdriver.h"
#define CLK 7//pins definitions for the driver
#define DIO 4
RGBdriver Driver(CLK,DIO);
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("red");
Driver.begin(); // begin
Driver.SetColor(255, 0, 0); //Red. first node data
Driver.end();
delay(4000);
Serial.println("green");
Driver.begin(); // begin
Driver.SetColor(0, 255, 0); //Green. first node data
Driver.end();
delay(4000);

Serial.println("blue");
Driver.begin();
Driver.SetColor(0, 0,255 );//Blue. first node data
Driver.end();
delay(4000);
}

ufo 回答了