Skip to content

Instantly share code, notes, and snippets.

@spuder
Last active Apr 19, 2021
Embed
What would you like to do?
Use an ATTiny 85 to 'push' momentary button
#include <avr/sleep.h>
#define adc_disable() (ADCSRA &= ~(1<<ADEN)) // disable ADC (before power-off)
int buttonPin = 0; // phyisical pin 5
int ledPin = 4; // physical pin 3
void setup() {
// https://www.notion.so/spencerowen/AtTiny-85-automated-chicken-coop-heater-596304ab6b3145769b92ddffdeb16b6f
// https://arduino.stackexchange.com/a/66655/27311
// https://electronics.stackexchange.com/a/521634/23954
// set pin to floating
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
// wait 2 seconds for electronics to fully power up
delay(2000);
// Simulate button press & turn on led
pinMode(buttonPin, OUTPUT);
digitalWrite(buttonPin, LOW);
digitalWrite(ledPin, HIGH);
// Hold button press for 3 seconds
delay(3000);
// Set pin to floating and turn off LED
pinMode(buttonPin, INPUT);
digitalWrite(ledPin, LOW);
// Go to sleep
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu();
}
void loop() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment