Skip to content

Instantly share code, notes, and snippets.

@kikermo
Created September 2, 2019 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kikermo/17f09b2e68d17d98bc1de3fd6b6e4da5 to your computer and use it in GitHub Desktop.
Save kikermo/17f09b2e68d17d98bc1de3fd6b6e4da5 to your computer and use it in GitHub Desktop.
Schedule sensor readings on Greenhouse project
#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