Before getting started, I prepared a simple Attiny85 Setup that consist of an Attiny Connected with a Buzzer and one LED.
I followed the below schematic for connection and made a Breadboard edition first.
I then programmed the attiny85 with my Arduino as ISP Programmer just by putting the attiny85 onto the IC Socket and flashing the MCU with the following sketch-
#define speakerPin 0
#define ledPin 2
void setup() {
pinMode(speakerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
randomSeed(analogRead(0));
}
void phrase1() {
int k = random(1000,2000);
digitalWrite(ledPin, HIGH);
for (int i = 0; i <= random(100,2000); i++){
tone(speakerPin, k+(-i*2)); delay(random(.9,2)); } digitalWrite(ledPin, LOW); for (int i = 0; i <= random(100,1000); i++){
tone(speakerPin, k + (i * 10)); delay(random(.9,2)); }
}
void phrase2() {
int k = random(1000,2000);
digitalWrite(ledPin, HIGH); for (int i = 0; i <= random(100,2000); i++){
tone(speakerPin, k+(i*2)); delay(random(.9,2)); } digitalWrite(ledPin, LOW); for (int i = 0; i <= random(100,1000); i++){
tone(speakerPin, k + (-i * 10)); delay(random(.9,2)); }
}
void loop() {
int K = 2000;
switch (random(1,7)) {
case 1:phrase1(); break;
case 2:phrase2(); break;
case 3:phrase1(); phrase2(); break;
case 4:phrase1(); phrase2(); phrase1();break;
case 5:phrase1(); phrase2(); phrase1(); phrase2(); phrase1();break;
case 6:phrase2(); phrase1(); phrase2(); break;
}
for (int i = 0; i <= random(3, 9); i++){
digitalWrite(ledPin, HIGH); tone(speakerPin, K + random(-1700, 2000)); delay(random(70, 170)); digitalWrite(ledPin, LOW); noTone(speakerPin); delay(random(0, 30)); } noTone(speakerPin); delay(random(2000, 4000)); //(1000, 2000)
}