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

View file

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

View file

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