From 94bf3c7e6413b591259bdb298b8f010a2ce748d1 Mon Sep 17 00:00:00 2001
From: user2684 <user2684@users.noreply.github.com>
Date: Sat, 29 Jul 2017 16:22:29 +0200
Subject: [PATCH] Added ability to turn the ADC off so save power (#97)

---
 NodeManager.cpp | 9 +++++++++
 NodeManager.h   | 2 ++
 README.md       | 6 ++++--
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/NodeManager.cpp b/NodeManager.cpp
index 47ce6d4..0e0eca1 100755
--- a/NodeManager.cpp
+++ b/NodeManager.cpp
@@ -3486,6 +3486,7 @@ void NodeManager::process(Request & request) {
     case 28: setInterruptMinDelta(request.getValueInt()); break;
     case 30: setSleepOrWait(request.getValueInt()); break;
     case 31: setRebootPin(request.getValueInt()); break;
+    case 32: setADCOff(); break;
     default: return; 
   }
   _send(_msg.set(function));
@@ -3655,6 +3656,14 @@ void NodeManager::setRebootPin(int value) {
   _reboot_pin = value;
 }
 
+// turn the ADC off so to save 0.2 mA
+void NodeManager::setADCOff() {
+  // Disable the ADC by setting the ADEN bit (bit 7) to zero
+  ADCSRA = ADCSRA & B01111111;
+  // Disable the analog comparator by setting the ACD bit (bit 7) to one
+  ACSR = B10000000;
+}
+
 // sleep if the node is a battery powered or wait if it is not for the given number of milliseconds 
 void NodeManager::sleepOrWait(long value) {
   // if the node is sleeping, sleep-or-wait is enabled and we need to sleep for a decent amount of time, call sleep() otherwise wait()
diff --git a/NodeManager.h b/NodeManager.h
index e9c3f3b..883b320 100755
--- a/NodeManager.h
+++ b/NodeManager.h
@@ -1435,6 +1435,8 @@ class NodeManager {
     void sleepOrWait(long value);
     // [31] set which pin is connected to RST of the board to reboot the board when requested. If not set the software reboot is used instead (default: -1)
     void setRebootPin(int value);
+    // [32] turn the ADC off so to save 0.2 mA
+    void setADCOff();
     // hook into the main sketch functions
     void before();
     void presentation();
diff --git a/README.md b/README.md
index 2b27720..122990f 100755
--- a/README.md
+++ b/README.md
@@ -340,10 +340,12 @@ The next step is to configure NodeManager with settings which will instruct how
     void setReportIntervalSeconds(int value);
     // [30] if set and when the board is battery powered, sleep() is always called instead of wait() (default: true)
     void setSleepOrWait(bool value);
-    // [31] set which pin is connected to RST of the board to reboot the board when requested. If not set the software reboot is used instead (default: -1)
-    void setRebootPin(int value);
     // sleep if the node is a battery powered or wait if it is not for the given number of milliseconds 
     void sleepOrWait(long value);
+    // [31] set which pin is connected to RST of the board to reboot the board when requested. If not set the software reboot is used instead (default: -1)
+    void setRebootPin(int value);
+    // [32] turn the ADC off so to save 0.2 mA
+    void setADCOff();
 ~~~
 
 ### Set reporting intervals and sleeping cycles
-- 
GitLab