Go Down

Topic: issue with If function (Read 272 times) previous topic - next topic

adop


Hello

here I am trying to remake an unconventional IR remote control (not working on RC5 RC6 Nec standards etc.)

I do not know the programming language at all, but I managed to search the net to create the code below

  it works in part compiles and uploads to my UNO card


I specify that the reading of the buttons is done well and that the part of generation of frames also works what does not work it is the "selection" of the frame that I want to send according to the button supported

info: pressing a button generates a low state on the UNO input

my problem is that the frame is not sent when a button is pressed


if a charitable soul can give me a little help

Code: [Select]
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
}

slipstick

Code: [Select]

if (pinBoutonUnlock == LOW) {

....
}

if (pinBoutonLock == LOW) {

I think you forgot the "etat" in front of both variable names. The pin numbers will never == LOW.

Steve


adop

Hi thanks for your reply

I have try with

Code: [Select]
if (etatBoutonUnlock == LOW) {

...

  }

}

if (etatBoutonUnlock == LOW) {

...
  }
 
 


but the result is same the my LED not blinking

adop

It's working !!!!

You are right it's the variable pinboutonUnlock and pinBOoutonLock was wrong

but by dint of tinkering in the code nothing else functioned

I took the code above and applied the corrections that you advised me and it works

thank you so much

Go Up