现在播完就停了!可以做到循环吗?
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define BUTTON_PIN 2
Adafruit_NeoPixel strip = Adafruit_NeoPixel(62, PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH; //布爾oldState =高;
int showType = 0;
void setup()
{
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off' 初始化所有像素“關”
}
void loop() { //空隙環(){
// Get current button state. 獲取當前按鈕狀態
bool newState = digitalRead(BUTTON_PIN); //布爾newState = digitalRead(BUTTON_PIN);
// Check if state changed from high to low (button press). 檢查狀態由高變低(按下按鈕)。
if (newState == LOW && oldState == HIGH) { //如果(newState ==低&& oldState == HIGH){
// Short delay to debounce button. //短延時去抖按鈕。
delay(20); //延遲(20);
// Check if button is still low after debounce. //檢查按鈕仍然偏低抖了。
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) { //如果(newState == LOW){
showType++;
if (showType > 2) // 如果(showType> 9)
showType=0;
startShow(showType);
}
}
// Set the last button state to the old state. //設置最後一個按鈕的狀態到老態。
oldState = newState;
}
void startShow(int i) { // 無效startShow(int i)以{
switch(i){ //開關(ⅰ){
case 0:rainbow(20); //案例7:彩虹(20);
break; //打破;
case 1: rainbowCycle(20); //殼體8:rainbowCycle(20);
break;
}
}
/////////////////////////////////////////////////////////////////
void rainbow(uint8_t wait) { //彩虹無效(uint8_t有等待){
uint16_t i, j;
for(j=0; j<256; j++) { // 對於(J = 0;Ĵ<256; J ++){
for(i=0; i<strip.numPixels(); i++) { // 對於(i = 0;我<strip.numPixels();我++){
strip.setPixelColor(i, Wheel((i+j) & 255)); // strip.setPixelColor(ⅰ,輪式((I + J)255));
}
strip.show();
delay(wait); //延遲(等待);
}
}
/////////////////////////////////////////////////////////////////
void rainbowCycle(uint8_t wait) { //無效rainbowCycle(uint8_t有等待){
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel //對於(J = 0;Ĵ<256 * 5; J ++){// 5個週期輪上的所有顏色
for(i=0; i< strip.numPixels(); i++) { //對於(i = 0;我<strip.numPixels();我++){
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); //strip.setPixelColor(我,車輪(((I * 256 / strip.numPixels())+ J)255));
}
strip.show();
delay(wait); //延遲(等待);
}
}
/////////////////////////////////////////////////////////////////
uint32_t Wheel(byte WheelPos) { //uint32_t的車輪(字節WheelPos){
WheelPos = 255 - WheelPos;
if(WheelPos < 85) { // 如果(WheelPos <85){
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); // 返回strip.Color(255 - WheelPos * 3,0 WheelPos * 3);
} else if(WheelPos < 170) { //}否則,如果(WheelPos <170){
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); // 返回strip.Color(0,WheelPos * 3,255 - WheelPos * 3);
} else { // }其他{
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); //返回strip.Color(WheelPos * 3,255 - WheelPos * 3,0);
}
}
|