[AppleScript] 纯文本查看 复制代码
#include <Adafruit_NeoPixel.h>
#include <avr/power.h>
// ***
// *** The first NeoPixel is connected to pin 0
// ***
#define NEO_PIXEL_PIN 0
// ***
// *** The pin on which the power LED is connected
// ***
#define POWER_LED_PIN 3
// ***
// *** Number of NeoPixels
// ***
#define NEO_PIXEL_COUNT 3
// ***
// *** Create the NeoPixel instance
// ***
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEO_PIXEL_COUNT, NEO_PIXEL_PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
// ***
// *** Trinket 16MHz
// ***
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
// ***
// *** Setup the power LED
// ***
pinMode(POWER_LED_PIN, OUTPUT);
// ***
// *** Turn the Power LED on
// ***
digitalWrite(POWER_LED_PIN, HIGH);
// ***
// *** Setup the strip
// ***
strip.begin();
strip.show();
}
void loop()
{
rainbowCycle(60);
}
void rainbowCycle(uint8_t wait)
{
uint16_t i, j;
for (j = 0; j < 256 * 5; j++)
{
// ***
// *** 5 cycles of all colors on wheel
// ***
for (i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);
}
}
uint32_t Wheel(byte WheelPos)
{
WheelPos = 255 - WheelPos;
if (WheelPos < 85)
{
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if (WheelPos < 170)
{
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}