Seems like an easy straightforward little program...I can get it to run a few loops but then it locks up after maybe 3 to 5 loops or sometimes not at all... not sure why?
hardware: adafruit trinket M0, 100 ohm resistor to piezo, adafruit neopixel jewel
Thank you for any tips!!
#include <Adafruit_NeoPixel.h> // include the Neopixel Library in this Sketch
#define LED_PIN 2 // Data out to strip
#define LED_COUNT 7 // how many pixels in entire strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN);//num pixels , pin
int PXL1[] = {0, 1, 2, 3, 4, 5, 6};
int pixelRingPos = 1;
const int BuzzerPin = 4;
int BuzzerPinState = LOW;
unsigned long previousMillis = 0;
int interval = 200; // initial interval at which to sound
int Tone = 3400;
int toneCount = 0;
void Larson() {//classic Larson scanner!
int pos = 0, dir = 1; // Position, direction of "eye"
for (int i = 0; i < 250; i++) {
int j;
strip.setPixelColor(pos - 2, 0x100000); // Dark red
strip.setPixelColor(pos - 1, 0x800000); // Medium red
strip.setPixelColor(pos , 0xFF3000); // Center pixel is brightest
strip.setPixelColor(pos + 1, 0x800000); // Medium red
strip.setPixelColor(pos + 2, 0x100000); // Dark red
strip.show();
delay(30);
for (j = -2; j <= 2; j++) strip.setPixelColor(pos + j, 0);
pos += dir;
if (pos < 0) {
pos = 1;
dir = -dir;
} else if (pos >= strip.numPixels()) {
pos = strip.numPixels() - 2;
dir = -dir;
}
}
}
void setup() {
pinMode(BuzzerPin, OUTPUT);
strip.begin();
strip.clear();
strip.show();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (BuzzerPinState == LOW) {
BuzzerPinState = HIGH;
//Serial.println(Tone);
tone(BuzzerPin, Tone);
toneCount++;
//Serial.println(toneCount);
strip.setPixelColor(PXL1[pixelRingPos], strip.Color(255, 0, 0)); // set array pixel red
strip.show();
} else {
BuzzerPinState = LOW;
noTone(BuzzerPin);
strip.setPixelColor(PXL1[pixelRingPos], strip.Color(0, 0, 0)); // set array pixel null
strip.show();
pixelRingPos++;
if (pixelRingPos > 6) {
pixelRingPos = 1;
}
}
}
if (toneCount >= 3) {
toneCount = 0;
interval = interval - 5;
Tone = Tone + 100;
if (Tone >= 5400) {
delay(2000);
noTone(BuzzerPin);
Larson();
strip.clear();
strip.show();
pixelRingPos = 0;
interval = 200;
Tone = 3500;
//insert device state change here, and signal to pololu to OFF
delay(5000);
}
}
}