Demo relais bistable (module bisrelay) Ce programme permet la commande de relais bistable à partir d'ordre donnés sur la liaison série :
** Demo Relais bistable **
1..3 : Relais
M : Marche
A : Arret
B : Boucle
Relais 2 -> Loop On Off On Off On Off On Off On Off On On
#include <avrio/delay.h>
#include <avrio/bisrelay.h>
#include <avrio/tc.h>
#include <avr/pgmspace.h>
#define BAUDRATE 115200
#define PORT "tty0"
#define LOOP_TIME 5000
int
main (void) {
int c, count;
int channel = -1;
bool state = false;
bool loop = false;
bool action = false;
stdout = serial_port;
stderr = serial_port;
stdin = serial_port;
sei();
printf_P (PSTR ("\n\n** Demo Relais bistable **\n"
"1..%d : Relais\n"
" M : Marche\n"
" A : Arret\n"
" B : Boucle\n"), BISRELAY_QUANTITY);
for (;;) {
if ( (c = getchar()) != EOF) {
switch (c) {
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
if (c - '0' <= BISRELAY_QUANTITY) {
channel = c - '0';
printf_P (PSTR ("\nRelais %u -> "), channel);
}
break;
case 'A':
case 'a':
if (channel != -1) {
state = false;
loop = false;
action = true;
}
break;
case 'M':
case 'm':
if (channel != -1) {
state = true;
action = true;
loop = false;
}
break;
case 'B':
case 'b':
if (channel != -1) {
loop = true;
count = 0;
printf_P (PSTR ("Loop "));
}
break;
default:
break;
}
}
if (action) {
if (state) {
}
else {
}
action = false;
printf ("%s ", state ? "On" : "Off");
}
if (loop) {
if (count-- == 0) {
count = LOOP_TIME / 100;
state = !state;
action = true;
}
}
}
return 0;
}