bonjour
voila je cherche à refabriquer une télécommande IR non conventionnel (ne travaillant pas sur les standards RC5 RC6 Nec etc.)
je ne connais pas du tout le langage de programmation mais j'ai réussi grace à des recherches sur le net à créer le code ci-dessous
il marche en partie se compile et se téléverse dans ma carte UNO
cependant je n'arrive pas à faire fonctionner les fonctions IF ( ...)
je précise que la lecture des boutons se fait bien et que la partie de génération de trames fonctionne aussi ce qui ne fonctionne pas c'est la "sélection" de la trame que je veux envoyer en fonction du bouton appuyé
info : l'appui sur un bouton génère un état bas sur l'entrée du UNO
si une âme charitable peut me filer un petit coup de pouce
int pinBoutonUnlock;
int pinBoutonLock;
#define Duty_Cycle 40 //in percent (10->50), usually 33 or 50
//TIP for true 50% use a value of 56, because of rounding errors
//TIP for true 40% use a value of 48, because of rounding errors
//TIP for true 33% use a value of 40, because of rounding errors
#define Carrier_Frequency 28200 //usually one of 38000, 40000, 36000, 56000, 33000, 30000
#define PERIOD (1000000+Carrier_Frequency/2)/Carrier_Frequency
#define HIGHTIME PERIOD*Duty_Cycle/100
#define LOWTIME PERIOD - HIGHTIME
#define txPinIR 8 //IR carrier output
unsigned long sigTime = 0; //use in mark & space functions to keep track of time
unsigned int Unlock[] = {8630, 2930, 950, 6830, 950, 10680, 950, 2930, 950, 10680, 950, 2930, 950, 10680, 950, 2930, 950, 10680, 950, 2930, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 10680, 950, 2930, 950, 6830, 950, 10680, 950, 6830, 950, 6830, 950, 16140, 8630, 2930, 950, 6830, 950, 10680, 950, 2930, 950, 10680, 950, 2930, 950, 10680, 950, 2930, 950, 10680, 950, 2930, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 10680, 950, 2930, 950, 6830, 950, 10680, 950, 6830, 950, 6830, 950, 16140}; //AnalysIR Batch Export (IRremote) - RAW
unsigned int Lock[] = {8630, 6830, 950, 6830, 950, 2930, 950, 10740, 950, 2930, 950, 10740, 950, 2930, 950, 10740, 950, 2940, 950, 10740, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 2930, 950, 10740, 950, 6830, 950, 2930, 950, 6830, 950, 6830, 950, 16140, 8630, 6830, 950, 6830, 950, 2930, 950, 10740, 950, 2930, 950, 10740, 950, 2930, 950, 10740, 950, 2940, 950, 10740, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 6830, 950, 2930, 950, 10740, 950, 6830, 950, 2930, 950, 6830, 950, 6830, 950, 16140}; //AnalysIR Batch Export (IRremote) - RAW
void setup() {
Serial.begin(9600);
pinBoutonUnlock=12;
pinBoutonLock=10;
pinMode(pinBoutonUnlock,INPUT);
pinMode(pinBoutonLock,INPUT);
pinMode(txPinIR,OUTPUT);
}
void loop() {
boolean etatBoutonUnlock=digitalRead(pinBoutonUnlock);
boolean etatBoutonLock=digitalRead(pinBoutonLock);
Serial.println(etatBoutonUnlock);
Serial.println(etatBoutonLock);
if (pinBoutonUnlock == LOW) {
sigTime = micros(); //keeps rolling track of signal time to avoid impact of loop & code execution delays
for (int i = 0; i < sizeof(Unlock) / sizeof(Unlock[0]); i++) {
mark(Unlock[i++]);
if (i < sizeof(Unlock) / sizeof(Unlock[0])) space(Unlock[i]);
}
}
if (pinBoutonLock == LOW) {
sigTime = micros(); //keeps rolling track of signal time to avoid impact of loop & code execution delays
for (int i = 0; i < sizeof(Lock) / sizeof(Lock[0]); i++) {
mark(Unlock[i++]);
if (i < sizeof(Lock) / sizeof(Lock[0])) space(Lock[i]);
}
}
delay(1000);
}
void mark(unsigned int mLen) { //uses sigTime as end parameter
sigTime+= mLen; //mark ends at new sigTime
unsigned long now = micros();
unsigned long dur = sigTime - now; //allows for rolling time adjustment due to code execution delays
if (dur == 0) return;
while ((micros() - now) < dur) { //just wait here until time is up
digitalWrite(txPinIR, HIGH);
delayMicroseconds(HIGHTIME - 5);
digitalWrite(txPinIR, LOW);
delayMicroseconds(LOWTIME - 6);
}
}
void space(unsigned int sLen) { //uses sigTime as end parameter
sigTime+= sLen; //space ends at new sigTime
unsigned long now = micros();
unsigned long dur = sigTime - now; //allows for rolling time adjustment due to code execution delays
if (dur == 0) return;
while ((micros() - now) < dur) ; //just wait here until time is up
}