Analog sensor example – Echelon Mini EVK User Manual

Page 56

Advertising
background image

// Latch the button inputs
io_out(ioButtonLd, 0);
io_out(ioButtonLd, 1);

// Shift in and return TRUE if any buttons are pressed
return !((unsigned) io_in(ioButtons) == 0xFF);
}

// 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 reads the MiniGizmo temperature sensor once
a second and sends its value to a network variable if it has changed, replacing the

console output of the previous analog sensor example. The output network

variable is a SNVT_temp_p value, which is a fixed-point scalar value
representing hundredths of degrees Celsius. The network variable 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 num_alias_table_entries 2
#pragma run_unconfigured

// Define the device interface
network output SNVT_temp_p nvoTemperature;

// 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]

50

Mini EVK User’s Guide

Advertising