Created
September 2, 2019 00:46
-
-
Save kikermo/17f09b2e68d17d98bc1de3fd6b6e4da5 to your computer and use it in GitHub Desktop.
Schedule sensor readings on Greenhouse project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Arduino.h> | |
#include "Timer.h" | |
int moistureSensorPin = A0; | |
const int SENSOR_EN_PIN = 13; | |
#define SAMPLE_PERIOD 10000 // Spacing between sample extraction in miliseconds | |
Timer timer; | |
void setup() { | |
pinMode(SENSOR_EN_PIN, OUTPUT); | |
digitalWrite(IRRIGATION_VALVE_PIN, LOW); | |
// Set up timer | |
int sensorReadEvent = timer.every(SAMPLE_PERIOD, readSensorsCallback, 0); | |
} | |
void loop() { | |
timer.update(); | |
} | |
void readSensorsCallback(void* context) { | |
//Sensor reading | |
digitalWrite(SENSOR_EN_PIN, HIGH); | |
delay(500); // Just to make sure the sensor is enabled when reading from it | |
uint8_t moistureVal = analogRead(moistureSensorPin); | |
bleHumidityC.notify8(moistureVal); | |
digitalWrite(SENSOR_EN_PIN, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment