Skip to content

Instantly share code, notes, and snippets.

@hdelei
Last active September 8, 2019 15:10
Show Gist options
  • Save hdelei/352dfcb8812a9f7045427bdbdd42e02b to your computer and use it in GitHub Desktop.
Save hdelei/352dfcb8812a9f7045427bdbdd42e02b to your computer and use it in GitHub Desktop.
Arduino Attiny85 algorithm to wake up USB soundcard device
#define adc_disable() (ADCSRA &= ~(1<<ADEN))
const int wakeUpPin = PB0;
const int powerCheckPin = PB1;
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time PB0 went HIGH
// constants won't change:
const long interval = 30000; // interval to check if sound card is sleeping (milliseconds)
void setup() {
pinMode(wakeUpPin, OUTPUT);
pinMode(powerCheckPin, INPUT);
//Other pins as Input with the purpose of saving energy
pinMode(PB2, INPUT);
pinMode(PB3, INPUT);
pinMode(PB4, INPUT);
//ADC disabled - energy save
adc_disable();
}
void loop() {
while(digitalRead(powerCheckPin)){
//do nothing while the card is ON (PB1 is HIGH)
}
// check to see if it's time to check for voltage in the powerCheckPin;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time voltage was checked
previousMillis = currentMillis;
// try to wakeup the Sound Card with a brief short circuit
//Provide a 20K resistor to avoid damage the board and USB port
digitalWrite(wakeUpPin, HIGH);
delay(10);
digitalWrite(wakeUpPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment