So I got new code to do my breathing LEDs, but I still have the same problem as before. All of my code runs fine together except the push button for blinking LED. It won't run when placed with the rest of the code, but runs on it's own. I've moved it around within the code, but can't figure out why it won't run.
So running all together and working is a breathing LED, with breathe speed controlled by a pot, and 5 various timed flashing LEDs. Just no button press for blinking LED (alarm activation).
(UPDATE)
And upon doing a little testing, the breathing and flashers work together just fine and the breathing and push to blink work together just fine. But the push to blink and flashers do not work together. Only the flashers run, but I can't activate the blinking LED. So it appears it's something to do with the flashers that's interfering with the push button activation.
// JUPITER 2 SKETCH for Adafruit Trinket Pro 3.3v
#include <Adafruit_NeoPixel.h>
#define PIN 3
#define signLED 4
#define POTPIN A6
#define ledOn LOW
#define ledOff HIGH
int potValue = 0;
int Speed = 0;
const int alarmLED = 1;
const int buttonPin = 0;
int ledState1 = ledOff; // the current state of the LED
int previousState = LOW; // the previous buttonState from the button pin
unsigned long buttonTime = 0; // The last time the output pin was toggled
unsigned long debounceTime = 400; // debounceTime time (I am using a noisy button)
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(3, PIN, NEO_GRB + NEO_KHZ800);
const uint8_t mySegment[3] = {0,1,2}; // LED strip setup
class Flasher
{
// Class Member Variables for BLINKING LEDs for CONSOLE FIBERS
// These are initialized at startup
int ledPin; // the number of the LED pin
long OnTime; // milliseconds of on-time
long OffTime; // milliseconds of off-time
// These maintain the current state
int ledState; // ledState used to set the LED
unsigned long previousMillis; // will store last time LED was updated
// Constructor - creates a Flasher
// and initializes the member variables and state
public:
Flasher(int pin, long on, long off)
{
ledPin = pin;
pinMode(ledPin, OUTPUT);
OnTime = on;
OffTime = off;
ledState = LOW;
previousMillis = 0;
}
void Update() // For flashing LEDs
{
// check to see if it's time to change the state of the LED
unsigned long currentMillis = millis();
if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
{
ledState = LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
{
ledState = HIGH; // turn it on
previousMillis = currentMillis; // Remember the time
digitalWrite(ledPin, ledState); // Update the actual LED
}
}
};
// Flashers for Main console & Freezing tubes
Flasher led1(9, 4500, 1800); // (pin#, on time, off time)
Flasher led2(10, 3500, 2000); // (pin#, on time, off time)
Flasher led3(11, 3000, 1000); // (pin#, on time, off time)
// Flashers for communication bay
Flasher led4(12, 6000, 1000); // (pin#, on time, off time)
Flasher led5(13, 4000, 500); // (pin#, on time, off time)
void setup() {
strip.begin(); // start LED strip for pulasating
strip.setBrightness(100); // Set LED strip brightness
strip.show(); // Initialize all pixels to 'off'
pinMode(signLED, OUTPUT);
pinMode(alarmLED, OUTPUT);
digitalWrite(alarmLED, ledState1);
digitalWrite(signLED, LOW);
}
void loop() {
// ALARM ACTIVATION
int buttonState = digitalRead(buttonPin);
if (buttonState != previousState && millis() - buttonTime > debounceTime) {
ledState1 = !ledState1;
buttonTime = millis();
}
if (ledState1 == ledOn) {
digitalWrite(alarmLED, (millis() >> 9) & 3); //Blink
digitalWrite(signLED, HIGH);
} else
digitalWrite(alarmLED, LOW);
digitalWrite(signLED, LOW);
previousState = buttonState;
// PULSATING THE WALL BEAMS
potValue = analogRead(POTPIN);
Speed = map(potValue, 0, 1023, 5, 80); // speed value of pulsating wall beam LEDs
breatheUpdate(mySegment, (Speed), 1, 5); // (speed,steps ,lowest brightness)
}
void breatheUpdate(const uint8_t * segment, const uint32_t increment, const uint8_t step, const uint8_t lowLimit)
{
static uint32_t lastTimeChange = 0;
static uint8_t direction = 1;
static uint8_t value = lowLimit;
if(millis() - lastTimeChange > increment)
{
value += (direction * step);
if (value <= lowLimit || value >= 255)
{
direction = direction * -1;
}
for(uint8_t i = 0; i < sizeof(segment) * 2; i++)
{
strip.setPixelColor(segment[i], strip.Color(value, value, value));
}
strip.show();
lastTimeChange += increment;
}
//Update flashing LED for consoles
led1.Update();
led2.Update();
led3.Update();
led4.Update();
led5.Update();
}