2017-11-09 08:39:35 +01:00
|
|
|
/*
|
|
|
|
* Sample arduino sketch using contiki features.
|
|
|
|
* We turn the LED off
|
|
|
|
* We allow read the moisture sensor
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-11-09 10:59:07 +01:00
|
|
|
#include "Servo.h"
|
2017-11-09 08:39:35 +01:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "arduino-process.h"
|
|
|
|
#include "rest-engine.h"
|
|
|
|
#include "net/netstack.h"
|
|
|
|
|
2017-11-17 13:43:35 +01:00
|
|
|
extern resource_t res_led, res_battery, res_cputemp, res_servo;
|
2017-11-09 10:59:07 +01:00
|
|
|
}
|
2017-11-09 08:39:35 +01:00
|
|
|
|
|
|
|
uint8_t led_pin=4;
|
|
|
|
uint8_t led_status;
|
|
|
|
|
|
|
|
int potpin = A5; // analog pin used to connect the potentiometer
|
|
|
|
int val; // variable to read the value from the analog pin
|
|
|
|
|
2017-11-09 10:59:07 +01:00
|
|
|
Servo servo; // create servo object to control a servo
|
2017-11-09 08:39:35 +01:00
|
|
|
|
|
|
|
void setup (void)
|
|
|
|
{
|
|
|
|
// switch off the led
|
|
|
|
pinMode(led_pin, OUTPUT);
|
|
|
|
digitalWrite(led_pin, HIGH);
|
|
|
|
led_status=0;
|
|
|
|
// Servo
|
|
|
|
servo.attach(3); // attaches the servo on pin 9 to the servo object
|
|
|
|
// init coap resourcen
|
|
|
|
rest_init_engine ();
|
|
|
|
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
|
|
|
rest_activate_resource (&res_led, "s/led");
|
|
|
|
rest_activate_resource (&res_battery, "s/battery");
|
|
|
|
rest_activate_resource (&res_cputemp, "s/cputemp");
|
2017-11-17 13:43:35 +01:00
|
|
|
rest_activate_resource (&res_servo, "a/servo");
|
2017-11-09 08:39:35 +01:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
|
|
|
// NETSTACK_MAC.off(1);
|
2017-11-09 10:59:07 +01:00
|
|
|
// mcu_sleep_set(128);
|
2017-11-09 08:39:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop (void)
|
|
|
|
{
|
|
|
|
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
|
|
|
|
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
|
|
|
|
servo.write(val); // sets the servo position according to the scaled value
|
|
|
|
}
|