Difference between revisions of "Sensor-LAMP"
From Microduino Wiki
(Created page with "{{Language|Microduino-LED Matrix}} {| style="width: 800px;" |- | thumb|400px|right ==Feature== *Adopt six WS2812 lights as the optical source. *An a...") |
m (Fengfeng moved page Microduino-LAMP to Sensor-LAMP) |
||
(One intermediate revision by one other user not shown) | |||
Line 20: | Line 20: | ||
==Document== | ==Document== | ||
− | + | ||
− | |||
===Main componet=== | ===Main componet=== | ||
*WS2812 wiki page: http://wiki.hacdc.org/index.php/WS2811_Digital_RGB_LED#Individual_LEDs | *WS2812 wiki page: http://wiki.hacdc.org/index.php/WS2811_Digital_RGB_LED#Individual_LEDs |
Latest revision as of 05:23, 22 July 2016
Language: | English • 中文 |
---|
ContentsFeature
Specification
DocumentMain componet
DevelopmentArduino Library and Support Package
ProjectVoice Control LightDebugging ProgramAdopt Adafruit_NeoPixel program example from Microduino IDE. Open IDE, click File→ Examples →Find LED_WS2812 #include <Adafruit_NeoPixel.h>
#define PIN 6 //Define control pin
// Parameter 1=Colored LED number in "strip".
// Para.2=Pin number
// Para.3=Colored LED type. Optional(Select one from the first two or the last two)
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
strip.begin();
strip.show(); //Initialize all light strips are out.
}
void loop()
{
// Method to lighten all lights.
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
rainbow(20);
rainbowCycle(20);
}
//"c"(color); All lights get lightened in order and it takes a few seconds for the next light to get lightened before the last one.
void colorWipe(uint32_t c, uint8_t wait)
{
for(uint16_t i = 0; i < strip.numPixels(); i++) //Get lightened in order.
{
strip.setPixelColor(i, c); //The function is used for lightening the "i" light strip with the "c" color.
strip.show(); //The function will display the control info. written by the function "setPixelColor".
delay(wait);
}
}
void rainbow(uint8_t wait) //Rainbow display
{
uint16_t i, j;
for(j = 0; j < 256; j++) //225 kinds of color change gradually
{
for(i = 0; i < strip.numPixels(); i++) //Light up the lights in sequence and wait for a few millisecond
{
strip.setPixelColor(i, Wheel((i + j) & 255));
}
strip.show();
delay(wait);
}
}
// Different from the function above, it adds rainbow loop.
void rainbowCycle(uint8_t wait)
{
uint16_t i, j;
for(j = 0; j < 256 * 5; j++) //The rainbow circulates for five times.
{
for(i = 0; i < strip.numPixels(); i++)
{
//Mathematical transformation added for the loop.
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
// Enter a number within 0-225 and get the only corresponding color.
// The color will change from red, green to blue and then red gradually and repeatedly.
uint32_t Wheel(byte WheelPos)
{
if(WheelPos < 85)
{
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if(WheelPos < 170)
{
//Since the WheelPos * 3 will surpass 255 under 85-170, it needs reduce 85 firstly.
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
else
{
// Since the WheelPos * 3 will surpass 255 under over 170, it needs reduce 170 firstly.
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} PurchasePictures |