Arduino プログラムで傾斜センサーを使用すると、次の問題が発生します。傾斜センサーがなければすべて正常に機能しますが、傾斜センサーを使用している間は機能が正しい順序で機能しません。
Hier まず、傾斜センサーのない私のバージョン。このバージョンは正常に動作します。私は5行で710個のLEDを使用しています。私は次々と始まる4つの機能を持っています。傾斜センサーを使用したいのと同じ原理。傾斜位置を変更すると、砂時計のように、ライト パネルの反対側からプログラムを開始する必要があります。
#include <Adafruit_NeoPixel.h>
#define PIN 6 // led
Adafruit_NeoPixel strip = Adafruit_NeoPixel(710, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
strip.begin();
strip.show();
}
void loop() {
colorWipe(strip.Color(255, 147, 41), 127);
colorWipe1(strip.Color(255, 147, 41), 127); //warm white
colorWipe2(strip.Color(1, 1, 1), 127); //black effect
colorWipe3(strip.Color(255, 147, 41), 127); //candle effect
}
void colorWipe(uint32_t c, uint8_t wait) {
int a;
int k, l, m, n, o;
for (a=1 ; a<600; a++) {
for (k=0,l=283,m=284,n=567,o=568 ;k<10,l<273,m<294, n<557, o<578; k++,l--,m++,n--,o++) {
strip.setPixelColor(k, random(250,255), random(142,149), random(35,43), random(35,120));
strip.setPixelColor(l, random(250,255), random(142,149), random(35,43), random(35,120));
strip.setPixelColor(m, random(250,255), random(142,149), random(35,43), random(35,120));
strip.setPixelColor(n, random(250,255), random(142,149), random(35,43), random(35,120));
strip.setPixelColor(o, random(250,255), random(142,149), random(35,43), random(35,120));
}
strip.show();
delay(random(50-70));
}
}
void colorWipe1(uint32_t c, uint8_t wait) {
int a, b;
int k, l, m, n, o;
int q, r, s, t, v;
int z=10, x;
for (b=1; b<141;b=b+random(0,2)) {
for (k=1+b,l=282-b,m=283+b,n=566-b,o=567+b ;k<11+b,l<273-b,m<292+b, n<557-b, o<576+b; k=k+random(0,2),l=l-random(0,2),m=m+random(0,2),n=n-random(0,2),o=o+random(0,2)) {
strip.setPixelColor(k, random(250,255), random(142,149), random(35,43), random(35,120));
strip.setPixelColor(l, random(250,255), random(142,149), random(35,43), random(35,120));
strip.setPixelColor(m, random(250,255), random(142,149), random(35,43), random(35,120));
strip.setPixelColor(n, random(250,255), random(142,149), random(35,43), random(35,120));
strip.setPixelColor(o, random(250,255), random(142,149), random(35,43), random(35,120));
delay(random(120-150));
}
strip.show();
delay(random(50-70));
}
}
void colorWipe2(uint32_t c, uint8_t wait) {
int a, b, d=0;
int k, l, m, n, o;
int q, r, s, t, v;
for (b=0; b<131; b=b+random(0,2)) {
for (k=0+b,l=283-b,m=284+b,n=567-b,o=568+b ;k<1+b,l<282-b,m<285+b, n<566-b, o<570+b; k=k+random(0,2),l=l-random(0,2),m=m+random(0,2),n=n-random(0,2),o=o+random(0,2)) {
strip.setPixelColor(k, 255, 147, 41, d);
strip.setPixelColor(l, 255, 147, 41, d);
strip.setPixelColor(m, 255, 147, 41, d);
strip.setPixelColor(n, 255, 147, 41, d);
strip.setPixelColor(o, 255, 147, 41, d);
delay(random(450-500));
}
strip.show();
delay(random(220-270));
}
}
void colorWipe3(uint32_t c, uint8_t wait) {
int a;
int k, l, m, n, o;
for (a=1 ; a<600; a++) {
for (k=132, l=151 , m=416 , n=435 , o=700 ;k<142, l>141, m<426, n>425, o<710; k++, l--, m++, n--, o++ ) {
strip.setPixelColor(k, random(250,255), random(142,149), random(35,43), random(55,180));
strip.setPixelColor(l, random(250,255), random(142,149), random(35,43), random(55,180));
strip.setPixelColor(m, random(250,255), random(142,149), random(35,43), random(55,180));
strip.setPixelColor(n, random(250,255), random(142,149), random(35,43), random(55,180));
strip.setPixelColor(o, random(250,255), random(142,149), random(35,43), random(55,180));
}
strip.show();
delay(random(50-70));
}
}
Hierは傾斜センサーを使用した例です。
int tilt_switch = 10;
#define PIN 6
#include <Adafruit_NeoPixel.h>
int tilt_switch_state = 0;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(710, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
strip.begin();
strip.show();
}
void loop() {
tilt_switch_state = digitalRead(tilt_switch);
//check to see if the tilt switch is closed
if (tilt_switch_state == HIGH) {
colorWipe(strip.Color(255, 147, 41), 127);
colorWipe1(strip.Color(255, 147, 41), 127);
}
if (tilt_switch_state == LOW) {
colorWipe3(strip.Color(255, 147, 41), 127);
}
}
void colorWipe(uint32_t c, uint8_t wait) {
int a;
int k, l, m, n, o;
int b;
int q, r, s, t, v;
int z = 10, x;
for (a = 1 ; a < 600; a++) {
for (k = 0, l = 283, m = 284, n = 567, o = 568 ; k < 10, l < 273, m < 294, n < 557, o < 578; k++, l--, m++, n--, o++) {
strip.setPixelColor(k, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
strip.setPixelColor(l, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
strip.setPixelColor(m, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
strip.setPixelColor(n, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
strip.setPixelColor(o, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
}
strip.show();
if (tilt_switch_state == HIGH) {
for (k = 132, l = 151 , m = 416 , n = 435 , o = 700 ; k<142, l>141, m<426, n>425, o < 710; k++, l--, m++, n--, o++ ) {
strip.setPixelColor(k, 1, 1, 1, 1);
strip.setPixelColor(l, 1, 1, 1, 1);
strip.setPixelColor(m, 1, 1, 1, 1);
strip.setPixelColor(n, 1, 1, 1, 1);
strip.setPixelColor(o, 1, 1, 1, 1);
}
break;
}
delay(random(50 - 70));
}
}
void colorWipe1(uint32_t c, uint8_t wait) {
int a, b;
int k, l, m, n, o;
int q, r, s, t, v;
int z = 10, x;
for (b = 1; b < 141; b = b + random(0, 2)) {
for (k = 1 + b, l = 282 - b, m = 283 + b, n = 566 - b, o = 567 + b ; k < 11 + b, l < 273 - b, m < 292 + b, n < 557 - b, o < 576 + b; k = k + random(0, 2), l = l - random(0, 2), m = m + random(0, 2), n = n - random(0, 2), o = o + random(0, 2)) {
strip.setPixelColor(k, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
strip.setPixelColor(l, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
strip.setPixelColor(m, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
strip.setPixelColor(n, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
strip.setPixelColor(o, random(250, 255), random(142, 149), random(35, 43), random(35, 120));
delay(random(120 - 150));
}
strip.show();
if(tilt_switch_state == HIGH){
for (k=132, l=151 , m=416 , n=435 , o=700 ;k<142, l>141, m<426, n>425, o<710; k++, l--, m++, n--, o++ ) {
strip.setPixelColor(k, 1, 1, 1, 1);
strip.setPixelColor(l, 1, 1, 1, 1);
strip.setPixelColor(m, 1, 1, 1, 1);
strip.setPixelColor(n, 1, 1, 1, 1);
strip.setPixelColor(o, 1, 1, 1, 1);
Serial.println("tilt3");
}
delay(random(50 - 70));
break;
}
}
void colorWipe3(uint32_t c, uint8_t wait) {
int a;
int k, l, m, n, o;
for (a = 1 ; a < 600; a++) {
for (k = 132, l = 151 , m = 416 , n = 435 , o = 700 ; k<142, l>141, m<426, n>425, o < 710; k++, l--, m++, n--, o++ ) {
strip.setPixelColor(k, random(250, 255), random(142, 149), random(35, 43), random(55, 180));
strip.setPixelColor(l, random(250, 255), random(142, 149), random(35, 43), random(55, 180));
strip.setPixelColor(m, random(250, 255), random(142, 149), random(35, 43), random(55, 180));
strip.setPixelColor(n, random(250, 255), random(142, 149), random(35, 43), random(55, 180));
strip.setPixelColor(o, random(250, 255), random(142, 149), random(35, 43), random(55, 180));
}
strip.show();
if (tilt_switch_state == LOW) {
for (k = 0, l = 283, m = 284, n = 567, o = 568 ; k < 10, l < 273, m < 294, n < 557, o < 578; k++, l--, m++, n--, o++) {
strip.setPixelColor(k, 1, 1, 1, 1);
strip.setPixelColor(l, 1, 1, 1, 1);
strip.setPixelColor(m, 1, 1, 1, 1);
strip.setPixelColor(n, 1, 1, 1, 1);
strip.setPixelColor(o, 1, 1, 1, 1);
Serial.println("tilt2");
}
break;
}
delay(random(50 - 70));
}
}
colorWipe と colorWipe3 の 2 つの関数 (ライト パネルの異なる側から開始) のみを使用すると正常に動作しますが、colorWipe の後に colorWipe1 を追加すると、次の間違いがあります。前の関数。
ありがとうアンディ