Permalink
Browse files

Bug fix for analogRead

  • Loading branch information...
1 parent 6a9e584 commit 8d907390d925c8bb218645a3a2833986d1fc65df @nathanchantrell committed Dec 24, 2012
View
2 TinyTX_LDR/TinyTX_LDR.ino
@@ -50,7 +50,9 @@ void loop() {
digitalWrite(9, HIGH); // set D9 high
delay(10);
+ bitClear(PRR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
tinytx.light = 1024-analogRead(0); // read the input pin (A0)
+ ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
digitalWrite(9, LOW); // set D9 low
tinytx.supplyV = readVcc(); // Get supply voltage
View
3 TinyTX_LDR_Meter/TinyTX_LDR_Meter.ino
@@ -58,7 +58,10 @@ void setup() {
void loop() {
+ bitClear(PRR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
powerReading = analogRead(powerPin); // calculate the average
+ ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
+
static boolean ledOn = false;
if (!ledOn && powerReading < 1010) {
View
4 TinyTX_TMP36/TinyTX_TMP36.ino
@@ -61,7 +61,11 @@ void loop() {
delay(10); // Allow 10ms for the sensor to be ready
+ bitClear(PRR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
+
analogRead(tempPin); // throw away the first reading
+
+ ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
for(int i = 0; i < 10 ; i++) // take 10 more readings
{
View
2 TinyTX_Water/TinyTX_Water.ino
@@ -52,7 +52,9 @@ void loop() {
digitalWrite(9, HIGH); // set D9 high
delay(10);
+ bitClear(PRR, PRADC); ADCSRA |= bit(ADEN); // Enable the ADC
int reading = analogRead(0);
+ ADCSRA &= ~ bit(ADEN); bitSet(PRR, PRADC); // Disable the ADC to save power
digitalWrite(9, LOW); // set D9 low
tinytx.supplyV = readVcc(); // Get supply voltage

0 comments on commit 8d90739

Please sign in to comment.