Wondering if anyone has had any similar issues with getting sketches to run on an Arduino Nano. I have some simple code just to do little light chases and the like (mostly bits of copied Neopixel libraries). The code does what I want and I'm really just using trial and error to learn the language in baby steps.
My problem is this: I can run the code and have everything behave but ONLY if I have the Arduino plugged into a mini USB cable. I normally use a robust 12v power supply but the code hangs up and gets really glitchy unless that USB cable is plugged in. It does NOT need to be plugged into a computer but if it's not plugged into the USB in some manner it will stop and freeze up at some point of in the sketch. This is the code I'm running below (one of them anyway). I have similar problems with anything I try on these strips regardless of how much current I draw. Less lights doesn't solve it. Is this normal?
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN 2
#define PIXEL_PIN 6
#define PIXEL_COUNT 60
#define horn 12
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show();
}
void loop() {
// Get current button state.
bool newState = digitalRead(BUTTON_PIN);
// Check if state changed from high to low (button press).
if (newState == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) {
}
// Set the last button state to the old state.
oldState = newState;
}
}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), 20); // Black/off
break;
case 1: colorWipe(strip.Color(255, 0, 0), 20); // Red
digitalWrite(horn, HIGH);
delay(3000);
colorWipe(strip.Color(0, 0, 0), 20); // Black/off
colorWipe(strip.Color(255, 0, 0), 20); // Red
colorWipe(strip.Color(0, 0, 0), 20); // Black/off
colorWipe(strip.Color(255, 0, 0), 20); // Red
colorWipe(strip.Color(255, 0, 0), 20); // Red
colorWipe(strip.Color(0, 0, 0), 20); // Black/off
colorWipe(strip.Color(0, 0, 0), 20); // Black/off
}
}