0

I'm new to this site and also the wonderful world of Arduino, I have been playing around with a Leonardo board and some Neopixel LEDS ( WS2812B ). I'm currently trying to set predefined colors on the LEDs with a single Pot, but also have an interrupt for a PIR sensor. I'm using the Fastled library since its great but at this point I seem to be stuck on the interrupt part. Any guidance will be appreciated !

#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);
}
Joel Spolsky
  • 33,372
  • 17
  • 89
  • 105
  • Could you define what you mean by `stuck`? Is your code not working? Have you tried any code for it? Did you get errors? Etc. Also, please try to format your code with consistent indentations, as it makes your code much more readable. Thanks! – Matt C Apr 15 '16 at 04:20
  • Also, your title is `multiple if statements for Arduino` and that doesn't explain a problem. It also isn't mentioned in your post. Perhaps you could find a title that better explains the issue. Just a friendly tip, you may want to read over this page: [The How-To-Ask Guide](https://stackoverflow.com/help/how-to-ask) so you can always be sure that your questions are easily answerable and as clear as possible. Be sure to include any efforts you've made to fix the problem you're having, and what happened when you attempted those fixes. Also don't forget to your show code and any error messages! – Matt C Apr 15 '16 at 04:25
  • Hello Matthew, Thank you for the reply, I will follow the guide next time thanks for Link, the problem is that the code will not compile the error I get is "Arduino: 1.6.8 (Mac OS X), Board: "Arduino Leonardo" Multiple_Ifs_Rev0:5: error: expected unqualified-id before numeric constant #define PIR_PIN 2 ^ /Users/MacBook/Desktop/Multiple_Ifs_Rev0/Multiple_Ifs_Rev0.ino:6:5: note: in expansion of macro 'PIR_PIN' int PIR_PIN = 0 – Coldkilla404 Apr 15 '16 at 17:12
  • Add this to your question. – Matt C Apr 15 '16 at 17:12
  • I'm using a pot to change the colors on a strip of Neopixels, the code works perfectly, but when I introduced the PIR as an interrupt to trigger the LEDS to go all white I would not compile, I'm sure I'm overlooking something important when attaching the interrupt. Thanks again for all your help – Coldkilla404 Apr 15 '16 at 17:14

0 Answers0