Hardware:
adafruit trinket M0
adafruit TDK piezo PS1240
adafruit Jewel
Grav charge models from etsy: https://www.etsy.com/listing/1247432778
100maH Lipo..the tiny one!
pololu mini push button power switch, LV
Siemens 3SU10016AA200AA0, Indicator Light, Red, Smooth Lens (just using the red lens)
short vid: https://www.youtube.com/watch?v=qzZ6tX6nk1A
Code: Select all
/* XRAD'S Mandalorian Grav Charge 9/19/2022
* Hardware: adafruit trinket M0
* adafruit TDK piezo PS1240
* adafruit Jewel
* Grav charge models from: https://www.etsy.com/listing/1247432778
* 100maH Lipo..the tiny one!
* pololu mini on off switch
* Siemens 3SU10016AA200AA0, Indicator Light, Red, Smooth Lens (just using the red lens)
* my youtube vid: https://www.youtube.com/watch?v=qzZ6tX6nk1A
*
* had to create a bit of non-blocking code to run the pixels and piezo at same time.
* I'm sure there is a better way, but this was straight-forward. feel free to use
* or modify as you like!
*/
#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
//pixel variables
int PXL1[] = {0, 1, 2, 3, 4, 5, 6};
int pixelRingPos = 1;
//piezo variables
const int BuzzerPin = 3;
int BuzzerPinState = LOW;
unsigned int Tone = 3500;//initial low tone
int toneCount = 0;
//piezo main delay
int previousMillis2 = 0;
int interval2 = 100;//interval no-tone gap
//piezo mini delay
unsigned long previousMillis = 0;
int interval = 50; // interval at which to sound
//leds
unsigned long previousMillis1;
int interval1 = 100;
int ledState = LOW;
void Larson() {//modified Larson scanner!
int pos = 0, dir = 1; // initial position, initial direction of "eye"
for (int i = 0; i < 200; i++) {
int j;
strip.setPixelColor(pos - 3, 0x100000); // Dark red
strip.setPixelColor(pos - 2, 0x100000); // Dark red
strip.setPixelColor(pos - 1, 0x800000); // Medium red
strip.setPixelColor(pos , 0xFFFFFF); // Center pixel is brightest, the 'eye'
strip.setPixelColor(pos + 1, 0x800000); // Medium red
strip.setPixelColor(pos + 2, 0x100000); // Dark red
strip.setPixelColor(pos + 3, 0x100000); // Dark red
strip.show();
delay(30);
for (j = -2; j <= 2; j++)
strip.setPixelColor(pos + j, 0);
pos += dir;
if (pos < 0) {
pos = random(1 - 6);
dir = -dir;
} else if (pos >= strip.numPixels()) {
pos = random(1 - 6);
dir = -dir;
}
}
strip.clear();
strip.show();
}
void setup() {
randomSeed(analogRead(20));
pinMode(BuzzerPin, OUTPUT);
strip.setBrightness(150);
strip.begin();
strip.clear();
strip.show();
}
void loop() {
unsigned long currentMillis = millis();
//piezo function
if (currentMillis - previousMillis2 >= interval2) {
previousMillis2 = currentMillis;
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (BuzzerPinState == LOW) {
BuzzerPinState = HIGH;
//Serial.println(Tone);
tone(BuzzerPin, Tone);
toneCount++;
//Serial.println(toneCount);
} else {
BuzzerPinState = LOW;
noTone(BuzzerPin);
}
}
}
//pixel function
if (currentMillis - previousMillis1 >= interval1) {
previousMillis1 = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
strip.setPixelColor(PXL1[pixelRingPos], strip.Color(255, 0, 0));
strip.show();
} else {
ledState = LOW;
strip.setPixelColor(PXL1[pixelRingPos], strip.Color(0, 0, 0));
strip.show();
pixelRingPos++;
if (pixelRingPos > 6) {
pixelRingPos = 1;
}
}
}
if (toneCount >= 4) {
toneCount = 0;
noTone(BuzzerPin);
Tone = Tone + 100;
if (Tone >= 4700) {
Tone = 4700;
tone(BuzzerPin, Tone);
delay(1500);
noTone(BuzzerPin);
Larson();
pixelRingPos = 1;
Tone = 3500;
//insert device state change here, and signal to pololu to OFF
delay(5000);
}
}
}