1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
#include <Servo.h>
Servo myservo; // create servo object to control a servo
#define INTERRUPTEUR 10
#define OEILG 14
#define OEILD 15
bool memoInter=false;
int bp1 = 0;
int bp1Mem = 0;
int ledOn = 1;
char str_BPH[]="278308";
char str_BPB[]="278305";
char str_BPS[]="278306";
char str_reception[]="";
void setup() {
//Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo.write(0);
pinMode(INTERRUPTEUR, INPUT); //interupteur (D10)
pinMode(OEILG, OUTPUT); //oeil 1 (A0)
pinMode(OEILD, OUTPUT); //oeil 2 (A1)
analogWrite(OEILG,0);
analogWrite(OEILD,0);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
}
void loop() {
// lit l'état actuel du bouton poussoir
bp1 = digitalRead(INTERRUPTEUR);
//reception RF
if (mySwitch.available()) {
sprintf(str_reception,"%ld", mySwitch.getReceivedValue());
if(strcmp(str_reception,str_BPH) == 0 || strcmp(str_reception,str_BPB) == 0 || strcmp(str_reception,str_BPS) == 0){
bp1=1;
}
mySwitch.resetAvailable();
}
// compare l'état actuel du bouton poussoir à l'état précédent mémorisé
if (bp1 != bp1Mem){
// si l'état du bouton poussoir a changé
// on mémorise l'état courant du bouton poussoir pour les prochains passages dans la boucle loop
bp1Mem = bp1;
// si ce nouvel état est passé à 1, on a donc un front montant.
if (bp1 == 1) {
//On change l'état de la variable de la led de 1 à 0 ou de 0 à 1
ledOn = !ledOn;
//Serial.println("ici");
if (ledOn == 1) {
analogWrite(OEILG,0);
analogWrite(OEILD,0);
myservo.write(0);
}else{
myservo.write(130);
delay(800);
analogWrite(OEILG,511);
analogWrite(OEILD,511);
}
}
}
bp1=0;
} |
Partager