AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
input/switch/demo_switch.c

Demo micro-switch (switch) Ce programme affiche l'état des interrupteurs en hexadécimal sur la liaison série.

#include <avrio/switch.h>
#include <avrio/tc.h>
/* constants ================================================================ */
#define BAUDRATE 115200
#define PORT "tty0"
/* main ===================================================================== */
int
main (void) {
xSwitch xPrev = 0;
xSwitch xCurrent;
// Configuration du port série par défaut (8N1, sans RTS/CTS)
xSerialIos settings = SERIAL_SETTINGS (BAUDRATE);
// Ouverture du port série en sortie
FILE * serial_port = xFileOpen (PORT, O_WRONLY, &settings);
stdout = serial_port; // le port série est la sortie standard
for (;;) {
xCurrent = xSwitchGet();
if (xCurrent != xPrev) {
xPrev = xCurrent;
printf ("%X\n", xCurrent);
}
}
return 0;
}
/* ========================================================================== */