// https://en.wikipedia.org/wiki/Pitch_(music)
// https://en.wikipedia.org/wiki/Piano_key_frequencies
// https://gist.github.com/mikeputnam/2820675 // pitches.h
#include <FastLED.h> // https://github.com/FastLED/FastLED
int hours = 3; // hours for pre-delay
#define PIN 4 // PWM for WS2812B DIN
#define LED 1 // WS2812B count
#define MAX 255 // Maximum brightness
#define MIN 0 // Minimum brightness
#define SPK 0 // speaker
#define LO 110 // lowest frequency
#define HI 1760 // highest frequency
CRGB leds[LED];
void setup() {
FastLED.addLeds<WS2812, PIN, GRB>(leds, LED);
FastLED.clear();
FastLED.setBrightness(255);
FastLED.show();
pinMode(SPK, OUTPUT);
// predelay(hours); // (hours) delay before light and sound
}
void loop() {
delay(75); // slow the tones
light();
sound();
}
void predelay(int hours) {
delay(hours * 3600 * 1000); // hours * seconds per hour * milliseconds
}
void light() {
// pixel random max R, G, B
leds[0] = CRGB(random(2) * random(MAX), // red
random(2) * random(MAX), // grn
random(2) * random(MAX)); // blu
FastLED.show();
}
void sound() {
int rnd = random(LO, HI); // delay for tones
for (int i = 0; i < 25; i++) { // squarewave
digitalWrite(SPK, HIGH);
delayMicroseconds(rnd);
digitalWrite(SPK, LOW);
delayMicroseconds(rnd);
}
}
/*************************************************************************************************
WS2812B +-- --+
VCC |-- --| DIN
DOT |-- --| GND
+-- --+
**************************************************************************************************
ATtiny85 +-- --+
PCINT5/-RESET/ADC0/dW/PB5 |1 * 8| VCC
PCINT3/XTAL1/CLKI/-OC1B/ADC3/PB3 |2 7| PB2/SCK/USCK/SCL/ADC1/T0/INT0/PCINT2
PWM4/PCINT4/XTAL2/CLKO/OC1B/ADC2/PB4 |3 6| PB1/MISO/DO/AIN1/OC0B/OC1A/PCINT1/PWM1
GND |4 5| PB0/MOSI/DI/SDA/AIN0/OC0A/-OC1A/AREF/PCINT0/PWM0
+-----+
*************************************************************************************************/