remove init pwm per default, switch moisture sensor on and off to save energy

This commit is contained in:
Harald Pichler 2014-12-12 08:47:01 +01:00
parent 76ea945fd7
commit df95393980
3 changed files with 20 additions and 5 deletions

View file

@ -56,17 +56,26 @@
PROCESS(arduino_sketch, "Arduino Sketch Wrapper");
#ifndef LOOP_INTERVAL
#define LOOP_INTERVAL (1 * CLOCK_SECOND)
#endif
PROCESS_THREAD(arduino_sketch, ev, data)
{
static struct etimer loop_periodic_timer;
PROCESS_BEGIN();
arduino_pwm_timer_init ();
adc_init ();
setup ();
/* Define application-specific events here. */
etimer_set(&loop_periodic_timer, LOOP_INTERVAL);
while (1) {
loop ();
/* Give other processes a chance to run */
PROCESS_PAUSE();
PROCESS_WAIT_EVENT();
if(etimer_expired(&loop_periodic_timer)) {
loop ();
etimer_reset(&loop_periodic_timer);
}
}
PROCESS_END();
}

View file

@ -53,13 +53,15 @@ RESOURCE(res_moisture,
NULL);
extern uint8_t moisture_pin;
extern uint8_t moisture_vcc;
extern uint16_t moisture_voltage;
static void
res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{
digitalWrite(moisture_vcc, HIGH);
moisture_voltage = analogRead(moisture_pin);
digitalWrite(moisture_vcc, LOW);
unsigned int accept = -1;
REST.get_header_accept(request, &accept);

View file

@ -15,6 +15,7 @@ extern "C" {
extern resource_t res_moisture, res_battery;
uint8_t moisture_pin = A5;
uint8_t moisture_vcc = 19;
uint16_t moisture_voltage = 0;
#define LED_PIN 4
@ -25,6 +26,9 @@ void setup (void)
// switch off the led
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
// init moisture sensor
pinMode(moisture_vcc, OUTPUT);
digitalWrite(moisture_vcc, LOW);
// init coap resourcen
rest_init_engine ();
rest_activate_resource (&res_moisture, "s/moisture");