setting up sleep for the arduino, adding mathod to calulate persentage of the potty
This commit is contained in:
parent
bcd25bd40a
commit
927fe3080f
@ -1,10 +1,16 @@
|
||||
#include <avr/sleep.h>
|
||||
|
||||
|
||||
float damppotty;
|
||||
void setup() {
|
||||
pinMode(2, INPUT);
|
||||
pinMode(A2, INPUT);
|
||||
pinMode(A4, INPUT);
|
||||
pinMode(9, OUTPUT);
|
||||
pinMode(7, OUTPUT);
|
||||
pinMode(5, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
Serial.begin(19200);
|
||||
digitalWrite(9 ,HIGH);
|
||||
|
||||
|
||||
}
|
||||
@ -13,4 +19,45 @@ void setup() {
|
||||
void loop() {
|
||||
Serial.println(digitalRead(2));
|
||||
delay(20);
|
||||
if (digitalRead(2) == 1) {
|
||||
sleep();
|
||||
} else {
|
||||
Serial.println("Skipping sleep");
|
||||
}
|
||||
Serial.println("continuing Main");
|
||||
delay(100);
|
||||
Serial.println(calculateTargetDampness() ,4);
|
||||
}
|
||||
|
||||
float calculateTargetDampness(){
|
||||
damppotty = analogRead(A2);
|
||||
return damppotty / 454 ;
|
||||
}
|
||||
|
||||
void sleep() {
|
||||
digitalWrite(9, LOW);
|
||||
Serial.println("Going to sleep");
|
||||
delay(10);
|
||||
sleep_enable();
|
||||
attachInterrupt(0, wakeUp, FALLING);
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
delay(10);
|
||||
sleep_cpu();
|
||||
}
|
||||
|
||||
void wakeUp() {
|
||||
// detachInterrupt(0);
|
||||
sleep_disable();
|
||||
Serial.println("woke up");
|
||||
//afterWakeup();
|
||||
}
|
||||
|
||||
void wait(int i){
|
||||
// A finction for consistent delays (only one point to adjust delay when clock speed is lowerd)
|
||||
delay(i);
|
||||
}
|
||||
|
||||
void afterWakeup(){
|
||||
delay(100);
|
||||
digitalWrite(9,HIGH);
|
||||
}
|
||||
|
1
src/arduinoNano/calibrateSleep.ino
Normal file
1
src/arduinoNano/calibrateSleep.ino
Normal file
@ -0,0 +1 @@
|
||||
|
Loading…
Reference in New Issue
Block a user