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

62 lines
1.6 KiB
Plaintext
Raw Normal View History

2015-11-20 14:08:43 +01:00
/*
* Sample arduino sketch using contiki features.
* We turn the LED off
* We allow read the poti 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.
*/
extern "C" {
#include "rest-engine.h"
#include "dev/servo.h"
2016-01-24 21:30:35 +01:00
#include "klin.h" // linera values lookup table
2015-11-20 14:08:43 +01:00
extern resource_t res_poti, res_battery;
uint8_t poti_pin = A5;
uint16_t poti_voltage = 0;
2015-12-22 06:37:40 +01:00
uint16_t servo_min= 1000;
uint16_t servo_max= 2000;
2015-11-20 14:08:43 +01:00
#define LED_PIN 4
}
//**********************scale**********************************
int scale (int in_min, int in_max, int out_min, int out_max, int wert)
{
2015-12-22 06:37:40 +01:00
int abc;
2015-11-20 14:08:43 +01:00
2015-12-22 06:37:40 +01:00
abc = ((long)out_max - (long)out_min)* ((long)wert-(long)in_min) / ( (long)in_max - (long)in_min);
abc = abc + out_min;
return (abc);
2015-11-20 14:08:43 +01:00
}
void setup (void)
{
// switch off the led
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
// init servo
servo_init();
// init coap resourcen
rest_init_engine ();
rest_activate_resource (&res_poti, "s/poti");
rest_activate_resource (&res_battery, "s/battery");
}
void loop (void)
{
2015-12-22 06:37:40 +01:00
int value;
2015-11-20 14:08:43 +01:00
poti_voltage = analogRead(poti_pin);
2015-12-22 06:37:40 +01:00
value=scale (345,868,servo_min,servo_max,poti_voltage);
2016-01-24 21:30:35 +01:00
uint16_t lookup_Daumengas(uint16_t i);
servo_set(1,lookup_Daumengas(value));
2015-12-22 06:37:40 +01:00
printf("%d,%d\n",poti_voltage,value);
2015-11-20 14:08:43 +01:00
}