Fix A0-A5 ADC constants, use in example sketch

This commit is contained in:
Ralf Schlatterbeck 2014-06-30 10:24:49 +02:00
parent 60156d1c48
commit 4b984153ab
4 changed files with 19 additions and 21 deletions

View file

@ -23,12 +23,12 @@
extern uint8_t pwm;
extern uint8_t period_100ms;
extern uint16_t analog1_voltage;
extern uint16_t analog2_voltage;
extern uint16_t analog5_voltage;
extern resource_t resource_led_pwm;
extern resource_t resource_led_period;
extern resource_t resource_analog1_voltage;
extern resource_t resource_analog2_voltage;
extern resource_t resource_analog5_voltage;
#endif // led_pwm_h

View file

@ -70,19 +70,19 @@ GENERIC_RESOURCE \
);
size_t
analog1_v (const char *name, uint8_t is_json, char *buf, size_t bufsize)
analog2_v (const char *name, uint8_t is_json, char *buf, size_t bufsize)
{
return snprintf
(buf, bufsize, "%d.%03d", analog1_voltage / 1000, analog1_voltage % 1000);
(buf, bufsize, "%d.%03d", analog2_voltage / 1000, analog2_voltage % 1000);
}
GENERIC_RESOURCE \
( analog1_voltage, METHOD_GET
, "analog/1"
, Analog 1 voltage
( analog2_voltage, METHOD_GET
, "analog/2"
, Analog 2 voltage
, V
, NULL
, analog1_v
, analog2_v
);
size_t

View file

@ -16,8 +16,8 @@ extern "C" {
#define LED_PIN 4
uint8_t pwm = 128;
uint8_t period_100ms = 10; /* one second */
uint16_t analog1_voltage = 0;
uint8_t period_100ms = 1; /* 1/10 second (period_100ms * 100ms) */
uint16_t analog2_voltage = 0;
uint16_t analog5_voltage = 0;
}
@ -26,7 +26,7 @@ void setup (void)
rest_init_engine ();
rest_activate_resource (&resource_led_pwm);
rest_activate_resource (&resource_led_period);
rest_activate_resource (&resource_analog1_voltage);
rest_activate_resource (&resource_analog2_voltage);
rest_activate_resource (&resource_analog5_voltage);
}
@ -34,8 +34,8 @@ void loop (void)
{
/* Use 255 - pwm, LED on merkur-board is wired to +3.3V */
analogWrite (LED_PIN, 255 - pwm);
analog1_voltage = analogRead (1) * 1600L / 1023L;
analog5_voltage = analogRead (5) * 1600L / 1023L;
analog2_voltage = analogRead (A2) * 1600L / 1023L;
analog5_voltage = analogRead (A5) * 1600L / 1023L;
printf ("clock : %u\nmillis: %lu\n", clock_time (), millis ());
delay (period_100ms * 100);
analogWrite (LED_PIN, 255); /* OFF: LED on merkur-board is wired to +3.3V */

View file

@ -57,14 +57,12 @@ const static uint8_t LED = 4;
const static uint8_t LED1 = 4;
const static uint8_t LED2 = 5;
const static uint8_t A0 = 15;
const static uint8_t A1 = 16;
const static uint8_t A2 = 17;
const static uint8_t A3 = 18;
const static uint8_t A4 = 19;
const static uint8_t A5 = 20;
//const static uint8_t A6 = 21;
//const static uint8_t A7 = 22;
const static uint8_t A0 = 7;
const static uint8_t A1 = 6;
const static uint8_t A2 = 5;
const static uint8_t A3 = 4;
const static uint8_t A4 = 0;
const static uint8_t A5 = 1;
// A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
// Only pins available for RECEIVE (TRANSMIT can be on any pin):