ルイージはこちら。LED 階段プロジェクトに 2 つの PIR センサーを追加するのに問題があります。(上下)。
両方の PIR は、Arduino Mega ボードの異なる 5v PIN とグループに接続されています。異なるストリップを接続する異なる PIN を使用しているため、LED のアレイを使用しています。(ケーブル管理のため、LED ストリップ自体からのデータを使用できませんでした)。
私は単純なコードに取り組んでいます。これは、センサーが 1 つある場合に正常に動作します。
int sensor = 37; // the pin that the sensor is atteched to
int state = LOW; // by default, no motion detected
int val = 0; // variable to store the sensor status (value)
#include <FastLED.h>
#define NUM_STRIPS 15
#define NUM_LEDS_PER_STRIP 20
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS
CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
void setup() {
delay(500); // initial delay 3 seconds
pinMode(leds, OUTPUT); // initalize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
FastLED.addLeds<WS2812B, 26>(leds, 0, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 27>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 28>(leds, 2 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 29>(leds, 3 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 30>(leds, 4 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 31>(leds, 5 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 32>(leds, 6 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 33>(leds, 7 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 34>(leds, 8 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 35>(leds, 9 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 40>(leds, 10 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 41>(leds, 11 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 42>(leds, 12 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 45>(leds, 13 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 44>(leds, 14 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
Serial.begin(9600); // initialize serial
}
void loop(){
val = digitalRead(sensor); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::White;
FastLED.show();
leds[i] = CRGB::White;
if (state == LOW) {
Serial.println("Motion detected!");
state = HIGH; // update variable state to HIGH
}
}
}
else {
for(int i = 0; i < NUM_LEDS; i++) {
FastLED.show();
leds[i] = CRGB::Black;
// delay 200 milliseconds
if (state == HIGH){
Serial.println("Motion stopped!");
state = LOW; // update variable state to LOW
}
}
}
}
しかし、2 番目の PIR を追加すると、期待どおりに動作しません。PIN 37 (ダウン) の PIR は非常に短い時間で 3 回トリガーされますが、PIN 49 (アップ) は期待どおりに動作します。
2 つの PIR のコードの下:
//SENSOR1
int sensor1 = 37; // the pin that the sensor is atteched to
int state1 = LOW; // by default, no motion detected
int val1 = 0; // variable to store the sensor status (value)
//SENSOR2
int sensor2 = 49; // the pin that the sensor is atteched to
int state2 = LOW; // by default, no motion detected
int val2 = 0; // variable to store the sensor status (value)
#include <FastLED.h>
#define NUM_STRIPS 15
#define NUM_LEDS_PER_STRIP 20
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS
CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
void setup() {
delay(500); // initial delay 3 seconds
pinMode(leds, OUTPUT); // initalize LED as an output
pinMode(sensor1, INPUT); // initialize sensor as an input
pinMode(sensor2, INPUT); // initialize sensor as an input
FastLED.addLeds<WS2812B, 26>(leds, 0, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 27>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 28>(leds, 2 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 29>(leds, 3 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 30>(leds, 4 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 31>(leds, 5 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 32>(leds, 6 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 33>(leds, 7 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 34>(leds, 8 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 35>(leds, 9 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 40>(leds, 10 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 41>(leds, 11 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 42>(leds, 12 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 45>(leds, 13 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
FastLED.addLeds<WS2812B, 44>(leds, 14 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
Serial.begin(9600); // initialize serial
}
void loop(){
val1 = digitalRead(sensor1); // read sensor value
if (val1 == HIGH) { // check if the sensor is HIGH
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::White;
FastLED.show();
leds[i] = CRGB::White;
if (state1 == LOW) {
Serial.println("SENSORE 37!");
state1 = HIGH; // update variable state to HIGH
delay (1500);
}
}
}
val2 = digitalRead(sensor2); // read sensor value
if (val2 == HIGH) { // check if the sensor is HIGH
for(int i = NUM_LEDS; i >0; i--) {
leds[i] = CRGB::White;
FastLED.show();
leds[i] = CRGB::White;
if (state2 == LOW) {
Serial.println("SENSORE 49!");
state2 = HIGH; // update variable state to HIGH
delay (1500);
}
}
}
else {
for(int i = 0; i < NUM_LEDS; i++) {
FastLED.show();
leds[i] = CRGB::Black;
// delay 200 milliseconds
if (state1 || state2 == HIGH ){
Serial.println("Motion stopped!");
}
}
}
}
何が起こっているのかわからず、数週間前からトラブルシューティングを行っているので、誰か助けてもらえますか?
ありがとうございます。重要な情報を見逃していた場合は、今すぐお知らせください