Hmm je vois. :~
Donc ma fonction serait
boolean bouton(int const bt, int i)
{
int val = digitalRead(bt);
int state = 0;
i--;
if((val != etat[i]) && (val == LOW))
{
state = 1;
}
else
{
state = 0;
}
etat[i] = val;
return state;
}
Code complet :
#include <VirtualWire.h>
const int bt1 = 2;
const int bt2 = 3;
const int bt3 = 4;
const int bt4 = 5;
const int bt5 = 6;
int etat[5] = {0};
void setup()
{
vw_setup(2000);
pinMode(bt1,INPUT);
pinMode(bt2,INPUT);
pinMode(bt3,INPUT);
pinMode(bt4,INPUT);
pinMode(bt5,INPUT);
}
void loop()
{
if (bouton(bt1,1))
{
radio_envoie("a");
}
if (bouton(bt2,2))
{
radio_envoie("b");
}
if (bouton(bt3,3))
{
radio_envoie("c");
}
if (bouton(bt4,4))
{
radio_envoie("d");
}
if (bouton(bt5,5))
{
radio_envoie("e");
}
}
void radio_envoie(char *msg)
{
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
}
boolean bouton(int const bt, int i)
{
int val = digitalRead(bt);
int state = 0;
i--;
if((val != etat[i]) && (val == LOW))
{
state = 1;
}
else
{
state = 0;
}
etat[i] = val;
return state;
}
Si je teste mes boutons, 2 ne fonctionne pas. (bouton 2 et bouton 5) Je vais regarder mon cablage, à première vue il a l'air correct.. =(