Analog sensor example – Echelon Mini EVK User Manual

Page 62

Advertising
background image

// Repeat every 50 milliseconds
mtimer repeating scanTimer = 50;

// Read the buttons when the timer expires
when(timer_expires(scanTimer)) {
boolean button;
static boolean lastButton;

button = GetButton();
if (button != lastButton) {
lastButton = button;
nvoSwitch.value = button ? 200U : 0;
nvoSwitch.state = button ? 1 : 0;
}
}

Analog Sensor Example

The following example application adds an Open Loop Sensor functional block to

the previous analog sensor example. The network variable output is changed to
be a member of the functional block. The functional block code is highlighted in

bold. A network tool such as the LonMaker Integration Tool is required to test

this application.

#pragma enable_io_pullups
#pragma enable_sd_nv_names
#pragma num_alias_table_entries 2
#pragma run_unconfigured

// Define the device interface
network output SNVT_temp_p nvoTemperature;

fblock SFPTopenLoopSensor {

nvoTemperature implements nvoValue;

} fbSwitch external_name("Temperature");

// Configure the I/O pins
IO_7 touch ioThermometer;

#define DS18S20_SKIP_ROM 0xCCu
#define DS18S20_CONVERT 0x44u
#define DS18S20_READ 0xBEu

// Get a temperature reading from the Touch temperature sensor
SNVT_temp_p GetTemperature(void) {
union {
SNVT_temp_p snvtTempP;
unsigned Bytes[2];
} CurrentTemperature;
CurrentTemperature.snvtTempP = 32767l;

if (touch_reset(ioThermometer)) {
(void) touch_byte(ioThermometer, DS18S20_SKIP_ROM);
(void) touch_byte(ioThermometer, DS18S20_READ);

CurrentTemperature.Bytes[1]
= touch_byte(ioThermometer, 0xFFu);
CurrentTemperature.Bytes[0]
= touch_byte(ioThermometer, 0xFFu);

if (touch_reset(ioThermometer)) {
// Scale the raw reading

56

Mini EVK User’s Guide

Advertising