Digital sensor and serial actuator example, Analog sensor and serial actuator example – Echelon Mini EVK User Manual

Page 51

Advertising
background image

Digital Sensor and Serial Actuator Example

The following example application reads the MiniGizmo push buttons every 50

milliseconds and sends an “On” or “Off” value to the serial port if it has changed.
A value of On means any of the buttons is pressed, and a value of Off means all

the buttons are off. The timer code is highlighted in bold.

#include <string.h>

#pragma num_alias_table_entries 2
#pragma run_unconfigured

// Configure the I/O pins
IO_4 input bitshift numbits(8) clockedge(-) ioButtons;
IO_6 output bit ioButtonLd = 1;
IO_10 output serial baud (4800) ioSerialOut;

// Read the MiniGizmo buttons
boolean GetButton(void) {
// 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);
}

// Send a string to the serial port
const char errorString[] = "String too long.";
void PrintConsole(const char *message) {
if (strlen(message) <= 100) {
io_out(ioSerialOut, message, (unsigned) strlen(message));
} else {
io_out(ioSerialOut, errorString,
(unsigned) strlen(errorString));
}
}

// 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;
PrintConsole(button ? "On\n\r" : "Off\n\r");

}

}

Analog Sensor and Serial Actuator Example

The following example application reads the temperature sensor once a second on

a MiniGizmo and sends its value to the serial port if it has changed. The timer
code is highlighted in bold.

#include <s32.h>
#include <string.h>

Mini EVK User’s Guide

45

Advertising