Hi all
Got a small problem with 2 neopixel rings. So in the loop I want them to both run the sequence together. The problem I'm having is that one ring will do the sequence, pause, then the other will do the sequence and so on. Is the issue in calling the digital read? If the sensor reads high then the ring in question will respond but it'll take a run through of the sequence to register.
It works perfectly when it's one in its own which leads me to think the problem is in the digital read line, any help would be greatly appreciated. Code is attached.
//
#include "FastLED.h" // Include Neopixel library
#define SPOT_1 12 // Defines pinouts for Neopixel rings
#define SPOT_2 9
#define SPOT_3 11
#define NUM_STRIPS 2
#define NUM_LEDS 16 // Number of neopixels per ring.
#define LED_TYPE NEOPIXEL // Defines use of neopixel chipset
CRGB spot1[NUM_LEDS], spot2[NUM_LEDS]; // Creates neopixel arrays
int HE1 = 18; // Sets Hall Effect Sensor pins
int HE2 = 21;
int HE1State = 0; // Sets initial sensor states to LOW
int HE2State = 0;
void setup() {
delay(100);
Serial.begin(9600);
FastLED.addLeds<LED_TYPE, SPOT_1>(spot1, NUM_LEDS); // Links all Neopixel rings to FastLED library.
FastLED.addLeds<LED_TYPE, SPOT_2>(spot2, NUM_LEDS);
pinMode(HE1, INPUT);
pinMode(HE2, INPUT);
}
void loop() {
Serial.println(F("Reading Signals "));
HE1State = digitalRead(HE1); // Look at reading all of the Hall Effect sensor inputs during the loop.
HE2State = digitalRead(HE2);
Serial.println(F("Signals read "));
if (HE1State == LOW) { //If sensor is LOW flash Red
flash();
Serial.println(F("HE1 Flash "));
}
if (HE1State == HIGH) { //If sensor is HIGH solid Blue
solid(); // Delay affects speed of circling light. Higher delay = slower speed.
Serial.println(F("HE1 Solid "));
}
if (HE2State == LOW) { //If sensor is LOW flash Red
flash2();
Serial.println(F("HE2 Flash "));
}
if (HE2State == HIGH) { //If sensor is HIGH solid Blue
solid2();
Serial.println(F("HE2 Solid "));
}
}
void flash() {
Serial.println(F("Sensor 1 Low "));
for (int i = 0; i < NUM_LEDS; i++) {
spot1[i] = CRGB::Red;
FastLED.show();
delay(30); // Delay affects speed of circling light. Higher delay = slower speed.
for (int i = 0; i < NUM_LEDS; i++)
spot1[i].fadeToBlackBy(50);
FastLED.show();
}
}
void solid() {
Serial.println(F("Sensor 1 High "));
fill_solid( spot1, NUM_LEDS, CRGB::Blue);
FastLED.show();
delay(1000); // Delay affects speed of circling light. Higher delay = slower speed.
}
void flash2() {
Serial.println(F("Sensor 2 Low "));
for (int i = 0; i < NUM_LEDS; i++) {
spot2[i] = CRGB::Red;
FastLED.show();
delay(30); // Delay affects speed of circling light. Higher delay = slower speed.
for (int i = 0; i < NUM_LEDS; i++)
spot2[i].fadeToBlackBy(50);
FastLED.show();
}
}
void solid2() {
Serial.println(F("Sensor 2 High "));
fill_solid( spot2, NUM_LEDS, CRGB::Blue);
FastLED.show();
delay(1000); // Delay affects speed of circling light. Higher delay = slower speed.
}
Cheers