Hi, I’ve uploaded the following program to a ATtiny85 with a USBasp. When I power the device it seems to run once, then stop.
int input = 0; // the sample right now
int avg = 450; // average, start at 1/2 scale
int env = 0; // envelope of audio
int filter = 15; // smoothing of average, bigger = more smooth
// Pin allocations for ATtiny85
int mic = 2;
int lights0 = 1;
int lights1 = 0;
int lights2 = 4;
void setup() {
pinMode(lights0, OUTPUT);
pinMode(lights1, OUTPUT);
pinMode(lights2, OUTPUT);
}
void loop() {
input = analogRead(mic); // read a sample
env = input - avg; // envelope is difference from average
if (env > 200) {
digitalWrite(lights0, HIGH);
digitalWrite(lights1, HIGH);
digitalWrite(lights2, HIGH);
}
if (env < 160) {
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
}
avg = (filter * avg + input) / (filter+1); // form the new
delay(1);
}
My connections into the ATtiny are correct (VCC -8, Mic analog - 3, GND -4, etc)
The code works fine on my Arduino Uno.
Does anyone have a reason why this would be?