2014-06-26 11:00:01 +02:00
|
|
|
/*
|
|
|
|
* Sample arduino sketch using contiki features.
|
|
|
|
* We turn the LED on and off and allow setting the interval and the
|
|
|
|
* brightness of the LED via coap.
|
|
|
|
* 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" {
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "led_pwm.h"
|
2014-06-29 18:06:48 +02:00
|
|
|
#define LED_PIN 4
|
2014-06-26 11:00:01 +02:00
|
|
|
|
2014-06-29 17:26:15 +02:00
|
|
|
uint8_t pwm = 128;
|
2014-06-30 10:24:49 +02:00
|
|
|
uint8_t period_100ms = 1; /* 1/10 second (period_100ms * 100ms) */
|
|
|
|
uint16_t analog2_voltage = 0;
|
2014-06-29 17:26:15 +02:00
|
|
|
uint16_t analog5_voltage = 0;
|
2014-06-26 11:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setup (void)
|
|
|
|
{
|
2014-12-29 08:16:47 +01:00
|
|
|
arduino_pwm_timer_init ();
|
2014-06-26 11:00:01 +02:00
|
|
|
rest_init_engine ();
|
2017-08-20 15:01:30 +02:00
|
|
|
rest_activate_resource (&res_led_pwm, (char *)"led/pwm");
|
|
|
|
rest_activate_resource (&res_led_period, (char *)"led/period");
|
|
|
|
rest_activate_resource (&res_analog2_voltage, (char *)"analog/2");
|
|
|
|
rest_activate_resource (&res_analog5_voltage, (char *)"analog/5");
|
2014-06-26 11:00:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop (void)
|
|
|
|
{
|
2014-06-26 18:37:13 +02:00
|
|
|
/* Use 255 - pwm, LED on merkur-board is wired to +3.3V */
|
|
|
|
analogWrite (LED_PIN, 255 - pwm);
|
2014-06-30 10:24:49 +02:00
|
|
|
analog2_voltage = analogRead (A2) * 1600L / 1023L;
|
|
|
|
analog5_voltage = analogRead (A5) * 1600L / 1023L;
|
2017-08-20 15:01:30 +02:00
|
|
|
printf ("clock : %lu\nmillis: %lu\n", clock_time (), millis ());
|
2014-06-26 18:37:13 +02:00
|
|
|
delay (period_100ms * 100);
|
|
|
|
analogWrite (LED_PIN, 255); /* OFF: LED on merkur-board is wired to +3.3V */
|
|
|
|
delay (period_100ms * 100);
|
2014-06-26 11:00:01 +02:00
|
|
|
}
|