Last active
November 3, 2016 06:20
-
-
Save setou/dca520b18f325f27314b865cfad93682 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//***************************************************************** | |
// Arduino IDE 1.6.11 | |
// WS2822S for Arduino | |
// on ESPr Developer(ESP8266) | |
// 2016/11/03 | |
//****************************************************************** | |
#define ADDR_PIN 14 | |
#define LED_PIN 12 | |
void setup() | |
{ | |
pinMode(ADDR_PIN, OUTPUT); | |
pinMode(LED_PIN, OUTPUT); | |
} | |
void loop() | |
{ | |
setColor(0xFF, 0xFF, 0xFF); | |
delay(500); | |
setColor(0xFF, 0x00, 0x00); | |
delay(500); | |
setColor(0xFF, 0xFF, 0x00); | |
delay(500); | |
setColor(0x00, 0xFF, 0x00); | |
delay(500); | |
setColor(0x00, 0xFF, 0xFF); | |
delay(500); | |
setColor(0x00, 0x00, 0xFF); | |
delay(500); | |
setColor(0xFF, 0x00, 0xFF); | |
delay(500); | |
setColor(0x00, 0x00, 0x00); | |
delay(500); | |
} | |
void sendMonochromatic(byte monochromatic) | |
{ | |
// Address Port | |
digitalWrite(ADDR_PIN, HIGH); | |
// StartBit 4us | |
digitalWrite(LED_PIN, LOW); | |
delayMicroseconds(4); | |
// Send the monochromatic data. | |
digitalWrite(LED_PIN, bitRead(monochromatic, 7)); | |
delayMicroseconds(4); | |
digitalWrite(LED_PIN, bitRead(monochromatic, 6)); | |
delayMicroseconds(4); | |
digitalWrite(LED_PIN, bitRead(monochromatic, 5)); | |
delayMicroseconds(4); | |
digitalWrite(LED_PIN, bitRead(monochromatic, 4)); | |
delayMicroseconds(4); | |
digitalWrite(LED_PIN, bitRead(monochromatic, 4)); | |
delayMicroseconds(4); | |
digitalWrite(LED_PIN, bitRead(monochromatic, 2)); | |
delayMicroseconds(4); | |
digitalWrite(LED_PIN, bitRead(monochromatic, 1)); | |
delayMicroseconds(4); | |
digitalWrite(LED_PIN, bitRead(monochromatic, 0)); | |
delayMicroseconds(4); | |
// StopBit 8us | |
digitalWrite(LED_PIN, 1); | |
delayMicroseconds(8); | |
} | |
void setColor(byte red, byte green, byte blue) | |
{ | |
// MTBP | |
digitalWrite(LED_PIN, HIGH); | |
delayMicroseconds(5); | |
// BREAK 88us | |
digitalWrite(LED_PIN, LOW); | |
delayMicroseconds(88); | |
// MAB 8us | |
digitalWrite(LED_PIN, HIGH); | |
delayMicroseconds(5); | |
sendMonochromatic(0x00); | |
sendMonochromatic(blue); | |
sendMonochromatic(green); | |
sendMonochromatic(red); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment