I find it hard to understand. How can I integrate your part code into mine?
Your code:
byte but = digitalRead (pinBut);
if (butState != but) {
butState = but;
delay (10); // debounce
if (LOW == but)
enable = ! enable;
My code:
#define RED 0x0 // Which LED to Strobe
#define BLUE 0x1
byte whichLED = RED; // Variable to track which LED is on
// constants won't change. Used here to set a pin number:
const int LED_Red = 11; // Where are the LEDs connected?
const int LED_Blue = 8;
const int strobeButton = A1;
byte Red_State = LOW; // State variables for the LEDs
byte Blue_State = LOW;
byte strobeButtonState = LOW;
bool enable = true;
unsigned long switchDelay = 250; // delay values changing flashing behavior
unsigned long strobeDelay = 50;
unsigned long strobeWait = strobeDelay; // Seed initial wait for strobe effect
unsigned long waitUntilSwitch = switchDelay; // seed initial wait, switch LEDs
unsigned long previousMillis = 0; // will store last time LED was updated
// Variables will change:
int pinArray[] = {8, 11};
int count = 0;
int timer = 50;
void setup() {
pinMode(LED_Red, OUTPUT);
pinMode(LED_Blue, OUTPUT);
pinMode(strobeButton, INPUT_PULLUP);
digitalWrite (LED_Red, HIGH);
digitalWrite (LED_Blue, LOW);
for (count = 0; count < 6; count++) {
pinMode(pinArray[count], OUTPUT);
}
}
void loop() {
strobeButtonState = digitalRead(A1);
if (strobeButtonState == LOW)
{
digitalWrite(LED_Red, Red_State); // each iteration of loop() sets the IO pins
digitalWrite(LED_Blue, Blue_State); // even if they don't change, that's okay
if ((long)(millis() - waitUntilSwitch)>=0)
{
Red_State = LOW;
Blue_State = LOW;
whichLED = !whichLED;
waitUntilSwitch += switchDelay;
}
if ((long)(millis() - strobeWait)>=0)
{
if (whichLED == RED)
Red_State = ! Red_State;
if (whichLED == BLUE)
Blue_State = ! Blue_State;
strobeWait += strobeDelay;
}
}
}