osd-contiki/examples/osd/arduino-wateralert/sketch.pde

50 lines
1.4 KiB
Plaintext
Raw Normal View History

2014-10-23 11:06:25 +02:00
/*
* Sample arduino sketch using contiki features.
* We turn the LED off
2014-12-07 21:39:46 +01:00
* We allow read the moisture sensor
2014-10-23 11:06:25 +02:00
* Unfortunately sleeping for long times in loop() isn't currently
* possible, something turns off the CPU (including PWM outputs) if a
* Proto-Thread is taking too long. We need to find out how to sleep in
* a Contiki-compatible way.
* Note that for a normal arduino sketch you won't have to include any
* of the contiki-specific files here, the sketch should just work.
*/
extern "C" {
2016-04-12 10:34:40 +02:00
#include "arduino-process.h"
2014-12-07 21:39:46 +01:00
#include "rest-engine.h"
2014-10-23 11:06:25 +02:00
extern volatile uint8_t mcusleepcycle; // default 16
2014-12-07 21:39:46 +01:00
extern resource_t res_moisture, res_battery;
uint8_t moisture_pin = A5;
uint16_t moisture_voltage = 0;
2015-02-05 13:44:05 +01:00
#define BUZZER_PIN 3 /* sig pin of the buzzer */
#define LED_PIN 4 /* LED Pin */
2014-10-23 11:06:25 +02:00
}
void setup (void)
{
2014-12-07 21:39:46 +01:00
// switch off the led
2014-10-23 11:06:25 +02:00
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
2015-02-05 13:44:05 +01:00
// setup Buzzer
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
2014-12-07 21:39:46 +01:00
// init coap resourcen
2014-10-23 11:06:25 +02:00
rest_init_engine ();
2014-12-07 21:39:46 +01:00
rest_activate_resource (&res_moisture, "s/moisture");
rest_activate_resource (&res_battery, "s/battery");
2014-10-23 11:06:25 +02:00
}
void loop (void)
{
2016-04-12 10:34:40 +02:00
mcu_sleep_off();
2015-02-05 13:44:05 +01:00
moisture_voltage = analogRead(moisture_pin);
if(moisture_voltage < 800){
digitalWrite(BUZZER_PIN, LOW);
}else{
digitalWrite(BUZZER_PIN, HIGH);
}
2016-04-12 10:34:40 +02:00
mcu_sleep_on();
2014-10-23 11:06:25 +02:00
}