Hello I am short on pins of ATtiny85. I must read button input from the reset pin but I don't want to destroy the programmer. I am planning to set the reset pin high internally and put a 20k resistor which is smaller than the input_Pullup resistor (50k) between the reset pin and ground. I shouldn't pull the reset pin to ground otherwise the MCU will reset but also I should be able to trigger the "pinchange" interrupt. Would the code below and the resistor I picked do the trick? Also is the pin number 5 correct for reset pin?
#define ButtonPin 5
unsigned long t1;
void setup() {
pinMode(ButtonPin, INPUT_PULLUP);
sbi(GIMSK, PCIE); //Turn on pin change interrupt
sbi(PCMSK,PCINT5); // Which pins are affected by the interrupt
}
ISR(PCINT0_vect){ // button interrupt
waitingbuttonresponse = true;
t1 = millis();
}
Also, I wanted to trigger another external interrupt on rising edge. The code is below, would it work? Notice I want to sleep the MCU that's why I can't detect rising or falling edges in the regular way using " MCUCR" register.
#define PIRPin 2
void setup() {
pinMode(PIRPin, INPUT);
GIMSK |= (1<<INT0);
}
ISR(INT0_vect){ // sensor interrupt
if (digitalRead(PIRPin)) waitingPIRresponse = true;
}
You can see that it makes a digital read to determine if it is high or low before giving the flag. I couldn't do the same for the button as the button is not pulled to ground completely.
One more thing is, I need to turn on a buzzer from a pin which I also must read potentiometer from. I am redefining buzzer pin as output each time I want to ring it, and I think AnalogRead() already defines the pin necessarily. So would the sample code below work? Notice A3 and pin3 are the same.
#define BuzzerPin 3 // Put 220R pulldown resistor to pot to prevent burns when pot is set small and buzzer activates
void loop(){
alarmDelay = map(analogRead(A3),0,1023,0,60);
delay(500);
pinMode(BuzzerPin,OUTPUT);
digitalWrite(BuzzerPin, HIGH);
delay(500);
alarmDelay = map(analogRead(A3),0,1023,0,60);
}
I am planning to use a MOSFET to act upon the voltage at the pin, I will apply voltage to ADC just for brief moment to read value and turn it off so no worries about buzzer being constantly on when potentiometer is turned to the right.