SHARE
TWEET

Untitled

a guest Sep 17th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define adc_disable() (ADCSRA &= ~(1<<ADEN))
  2.  
  3. const int wakeUpPin = PB0;
  4. const int powerCheckPin = PB1;
  5.  
  6. // Generally, you should use "unsigned long" for variables that hold time
  7. // The value will quickly become too large for an int to store
  8.  
  9. unsigned long previousMillis = 0;        // will store last time PB0 went HIGH
  10.  
  11. // constants won't change:
  12. const long interval = 30000;           // interval to check if sound card is sleeping (milliseconds)
  13.  
  14. void setup() {    
  15.   pinMode(wakeUpPin, OUTPUT);
  16.   pinMode(powerCheckPin, INPUT);
  17.  
  18.   //Other pins as Input with the purpose of saving energy
  19.   pinMode(PB2, INPUT);
  20.   pinMode(PB3, INPUT);  
  21.   pinMode(PB4, INPUT);
  22.   //ADC disabled - energy save
  23.   adc_disable();  
  24. }
  25.  
  26. void loop() {
  27.   while(digitalRead(powerCheckPin)){
  28.     //do nothing while the card is ON (PB1 is HIGH)        
  29.   }
  30.  
  31.   // check to see if it's time to check for voltage in the powerCheckPin;  
  32.   unsigned long currentMillis = millis();
  33.  
  34.   if (currentMillis - previousMillis >= interval) {
  35.     // save the last time voltage was checked
  36.     previousMillis = currentMillis;
  37.    
  38.     // try to wakeup the Sound Card with a brief short circuit
  39.     //Provide a 20K resistor to avoid damage the board and USB port
  40.     digitalWrite(wakeUpPin, HIGH);
  41.     delay(10);
  42.     digitalWrite(wakeUpPin, LOW);    
  43.   }
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top