Hi,
I want to wake the AirBoard< http://www.theairboard.cc/> which is Arduino compatible from a capacitive touch sensor. Be sure there is only one AD input, I have choosen the ADCTouch library.
Beacuse of this ADC convertor, I have choosen the sleep mode ADC. I did a very simple test, control the LED in using ADC sleep mode. But there are problems. When I am in the sleep mode, LED blinks with weak current, I don't know why it appeared this current? Anyone knows?
Or maybe I can use the Analogical Comparator Interrrupt?
#include <ADCTouch.h>
#include <avr/sleep.h>
#include <avr/power.h>
int ref; //reference values to remove offset
const int LED1=12;
const int LED2=13;
const int adcPin=5;
// when ADC completed, take an interrupt
EMPTY_INTERRUPT (ADC_vect);
// in sleep mode (ADC)
void sleepNow (const byte port)
{
cli();
bitSet (DIDR0, ADC0D); // disable digital buffer on A0
bitSet (DIDR0, ADC1D); // disable digital buffer on A1
bitSet (DIDR0, ADC2D); // disable digital buffer on A2
bitSet (DIDR0, ADC3D); // disable digital buffer on A3
bitSet (DIDR0, ADC4D); // disable digital buffer on A4
ADCSRA = bit (ADEN) | bit (ADIE) | bit (ADIF); // turn ADC on, want interrupt on completion
ADCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2); // prescaler of 128
ADMUX = bit (REFS0)|bit (REFS1)| (port & 0x07);
set_sleep_mode (SLEEP_MODE_ADC);
noInterrupts ();
// sleep during sample
sleep_enable();
ADCSRA |= bit (ADSC) | bit (ADIE);
int value= ADCTouch.read(A5, 500); //create reference values to
//account for the capacitance of the pad
value-=ref;
if(value>15) // value tested
{
interrupts ();
sleep_cpu ();
sleep_disable ();
}
while (bit_is_set (ADCSRA, ADSC))
{ }
// awake again
} // end of sleep
void setup ()
{
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW);
pinMode(LED2, OUTPUT);
digitalWrite(LED2, LOW);
ref = ADCTouch.read(A5, 500); //create reference values to
//account for the capacitance of the pin
} // end of setup
void loop () {
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
delay(2000);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
delay(1000);
sleepNow(adcPin);
}