0

我是这个网站的新手,也是 Arduino 的美妙世界,我一直在玩 Leonardo 板和一些 Neopixel LED(WS2812B)。我目前正在尝试使用单个 Pot 在 LED 上设置预定义的颜色,但也有 PIR 传感器的中断。我正在使用 Fastled 库,因为它很棒,但此时我似乎被困在中断部分。任何指导将不胜感激!

#include "FastLED.h"
#define NUM_LEDS 3
#define DATA_PIN 6
#define PIR_PIN 2

int PIR_PIN = 0

// These constants won't change:
const int analogPin = A0;    // pin that the sensor is attached to

CRGB leds[NUM_LEDS];

void setup() {
  // initialize the LED pin as an output:
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

  // initialize serial communications:
  pinMode(PIR_PIN, INPUT);
  attachInterrupt(0, PIR_PIN, CHANGE);   
}

void loop() {
  // read the value of the potentiometer:
  int analogValue = analogRead(analogPin);

  if (analogPin < 1000)
  {
    leds[0] = CRGB::Red;
    FastLED.show();// do Thing A
  }
  else if (analogPin < 500)
  {
    leds[0] = CRGB::Orange;
    FastLED.show();// do Thing B
  }
  else if (analogPin < 250)
  {
    leds[0] = CRGB::Green;
    FastLED.show();//do fuckity 
  } 
  else
  {
    leds[0] = CRGB::Purple;
    FastLED.show();// do Thing C
  }
}

void PIN_PIR () {
  buttonState = digitalRead(PIR_PIN);
  digitalWrite(DATA_PIN, buttonState);
}
4

0 回答 0