想在室內營造一點小氛圍不,話說工程師工做繁忙也得本身造些情調不是。這我是在pcDuino上作的,接一個燈帶驅動模塊LED strip driver,連接文章裏用的Arduino,附有程序代碼,在pcDuino上點亮的話程序代碼我也會附上的。爲了使效果更好,LED燈帶我設計的是呼吸燈哦! php
LED strip driver模塊 node
LED燈帶(5m) git
接線很簡單
LED strip driver CLK –> pcDuino D2
LED strip driver DIN –> pcDuino D3 ubuntu
打開ubuntu編譯運行程序代碼 api
點亮後的5m燈帶效果,這裏是拍出來的照片,燈帶亮度逐漸變化的效果不是很明顯,可是它是會「呼吸」的,很漂亮吧 oop
程序代碼: ui
#include "core.h" #define uint8_t unsigned char #define uint32_t unsigned long uint8_t Clkpin; uint8_t Datapin; void RGBdriver(uint8_t Clk, uint8_t Data) { Clkpin = Clk; Datapin = Data; pinMode(Datapin, OUTPUT); pinMode(Clkpin, OUTPUT); } void ClkRise(void) { digitalWrite(Clkpin, LOW); delayMicroseconds(1); digitalWrite(Clkpin, HIGH); delayMicroseconds(1); } void Send32Zero(void) { unsigned char i; for (i=0; i<32; i++) { digitalWrite(Datapin, LOW); ClkRise(); } } void begin(void) { Send32Zero(); } void end(void) { Send32Zero(); } uint8_t 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 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 SetColor(uint8_t Red,uint8_t Green,uint8_t Blue) { uint32_t dx = 0; dx |= (uint32_t)0x03 << 30; // highest two bits 1錛宖lag 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); } void setup() { RGBdriver(2,3); } void loop() { unsigned int i; while(1) { for(i = 0;i < 256;i ++) { begin(); // begin SetColor(0,0,i); //Blue. First node data. SetColor(R,G,B) end(); //delay(1); } for(i = 255;i > 0;i --) { begin(); // begin SetColor(0,0,i); //Blue. first node data end(); //delay(1); } } }