Hi
I am both new on here and new to Arduino programming so please excuse any inadvertent fopars
I am trying to write a simple sketch that switches from one routine to another on a button push
I can get a button to work
I can get both routines to work flawlessly in separate sketches without adding a button but as soon as I try to use a button to call either routine the routine freezes
what I want is
button LOW - routine 1 runs
button High - routine 2 runs
To my way of thinking it should go something like this:-
get button state - if high then routine 2
else routine 1
Here is routine 1
I have rem'd out the button test here
I have tried running serial write to sus whats going on but I can't get that to work on this sketch either ![]()
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
const int buttonPin = 2;
int buttonState = 0;
int dimFlag = 0;
int tOff = 0;
int stb = 0;
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
buttonState = digitalRead(buttonPin);
//if (buttonState == HIGH)
testOn(strip.Color(222,0,0),50);
delay(750);
//else
}
//Test On
void testOn(uint32_t c, uint8_t wait) {
if (dimFlag == 0)
strip.setBrightness(20);
else if (dimFlag == 1)
strip.setBrightness (75);
else strip.setBrightness (255);
dimFlag++;
if (dimFlag >2)
dimFlag = 0;
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
and here is the second routine
{
testOff(strip.Color(222,0,0),50);
stb++;
}
void testOff(uint32_t c, uint8_t wait) {
stb == 0;
if (stb == 0)
colorWipe(strip.Color(50, 30, 0), 200);
else
if (tOff == 0)
strip.setBrightness(255);
if (tOff == 5) strip.setBrightness (5);
tOff++;
//if (tOff >6)
// tOff = 0;
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
Been on this all day now and I just can't see it ![]()
Many thanks for any help
