salut a tous mon projet au début fonctionne j ai réaliser une boite d envol pour la fauconnerie et le code fonctionne pour les intéresses voici le code
#include <RCSwitch.h>
#define code 1400660// code decrypter avec receive demo
#include <Servo.h>
Servo myservo;
int pos = 0;//position servo//
const int ledPin = 13;
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0);//recepteur pin 2
pinMode(ledPin, OUTPUT);//
myservo.attach(9);//servo pin 9
myservo.write(0); //initialise le servo en position repos zero
delay(20); // pour stabilisation
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
while (!Serial) ;
switch (value) {
case code:
digitalWrite(ledPin, HIGH); // led ON
myservo.write(125); // va en butée inverse
delay(2000); // stabilisation 200 ms
digitalWrite(ledPin, LOW); // led OFF
myservo.write(0); // retour en zero
delay(20); // pour stabilisation
break;
}
mySwitch.resetAvailable();
}
}
maintenant je souhaite pouvoir enregistrer le code directement sur le terrain et non sans pc en passant par eeprom
j arrive bien a décode et enregistrer le code
mais impossible de faire une commande a la réception du code enregistrer
#include <EEPROM.h>
#include <Servo.h>
Servo myservo;
int pos = 125;
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int temps_defini =3000;
int boutonPin = 8;
unsigned long debut_appui;
boolean variable = false;
int etat_bouton;
int dernier_etat_bouton = LOW;
void EEPROMWritelong(int address, long value)
{
//Decomposition from a long to 4 bytes by using bitshift.
//One = Most significant -> Four = Least significant byte
byte four = (value & 0xFF);
byte three = ((value >> 8) & 0xFF);
byte two = ((value >> 16) & 0xFF);
byte one = ((value >> 24) & 0xFF);
//Write the 4 bytes into the eeprom memory.
EEPROM.write(address, four);
EEPROM.write(address + 1, three);
EEPROM.write(address + 2, two);
EEPROM.write(address + 3, one);
}
//This function will return a 4 byte (32bit) long from the eeprom
//at the specified address to address + 3.
long EEPROMReadlong(long address)
{
//Read the 4 bytes from the eeprom memory.
long four = EEPROM.read(address);
long three = EEPROM.read(address + 1);
long two = EEPROM.read(address + 2);
long one = EEPROM.read(address + 3);
//Return the recomposed long by using bitshift.
return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
}
void setup() {
pinMode(boutonPin, INPUT);
mySwitch.enableReceive(0);//receteur pin 2
Serial.begin(9600);
myservo.attach(9);
myservo.write(125); //initialise le servo en position repos zero
delay(20); // pour stabilisatio
}
void loop() {
etat_bouton = digitalRead(boutonPin);
mySwitch.available();
if (etat_bouton == HIGH && dernier_etat_bouton == LOW){
debut_appui = millis();
variable = true;
}
if ( variable == true && etat_bouton ==HIGH && dernier_etat_bouton == HIGH){ //LOW HIGH
if ((millis() - debut_appui) >= temps_defini){
int value = mySwitch.getReceivedValue();
if (value == 0) {
} else {
Serial.print( mySwitch.getReceivedValue());
long address=0;
EEPROMWritelong(address, mySwitch.getReceivedValue() );
address+=4;
delay (3000);
mySwitch.resetAvailable();
}
}
}
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();
while (!Serial) ;
switch (value = (EEPROMReadlong(0))) {
Serial.print("allume ");
Serial.println(EEPROMReadlong(0));
myservo.write(125); // va en butée inverse
delay(2000); // stabilisation 250 ms digitalWrite(ledPin, LOW); // led OFF
myservo.write(0); // retour en zero
delay(20); // pour stabilisation
break;
}
mySwitch.resetAvailable();
}
dernier_etat_bouton = etat_bouton;
}
avais vous une idée?
merci!