Fix the universal ir remote sketch

for all users in this forum, can you guys help me to fix what is wrong from this sketch so it does not work ...

i want to make ir remote sketch like orvibo or universal xiaomi remote but it does not work and i do not know the location of my sketch error ...

#define IRpin_PIN PIND
#define IRpin 2
char val;

// The maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000

// Timing resolution
#define RESOLUTION 20

int IRledPin = 3; // IR emitter LED connected to digital pin 3

int buttonState1 = 0;
int buttonState2 = 0;

// Store up to 100 pulse pairs
uint16_t pulses[300][2]; // Pair is high and low pulse
uint8_t currentpulse = 0; // Index for pulses we're storing
uint8_t sendpulse = 0; // Index for send pulses

void setup(void) {
// Set uart baudrate
Serial.begin(9600);

}

void loop(void) {

if( Serial.available() >0 ) {
val = Serial.read();
Serial.println(val);}

/============================================================================================================================================================================================================================/
if (val == 'A') {
Serial.println("Sending IR signal");

SendIRCode();
//delay(15); // wait 15 milliseconds before sending it again
//SendIRCode(); // repeat IR code if it is neccesary
Serial.println(sendpulse);

delay(5000); // wait 5 seconds to resend the code
}
/============================================================================================================================================================================================================================/
if ((val == 'a') || (currentpulse != 0)){

if (val == 'a'){
Serial.println("Ready to decode IR!");
}

/============================================================================================================================================================================================================================/
uint16_t highpulse, lowpulse; // Temporary storage timing
highpulse = lowpulse = 0; // Start out with no pulse length

while (IRpin_PIN & (1 << IRpin)) {
// count off another few microseconds
highpulse++;
delayMicroseconds(RESOLUTION);

// If the pulse is too long, we 'timed out' - either nothing
// was received or the code is finished, so print what
// we've grabbed so far, and then reset
if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
sendpulse=currentpulse;
currentpulse=0;
return;
}
}
// we didn't time out so lets stash the reading
pulses[currentpulse][0] = highpulse;

// same as above
while (! (IRpin_PIN & _BV(IRpin))) {
// pin is still LOW
lowpulse++;
delayMicroseconds(RESOLUTION);
if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
sendpulse=currentpulse;
currentpulse=0;
return;
}
}
pulses[currentpulse][1] = lowpulse;

// we read one high-low pulse successfully, continue!
currentpulse++;

}
}

void printpulses(void) {

// Start declaration
Serial.print("unsigned int ");
Serial.print("rawData[");
Serial.print((currentpulse *2)-1, DEC);
Serial.print("] = {");

for (uint8_t i = 0; i < currentpulse; i++) {
if (i != 0){

Serial.print("");
Serial.print(pulses_[0] * RESOLUTION);_

  • Serial.print(", ");*
  • }*
  • Serial.print("");*
    Serial.print(pulses_[1] * RESOLUTION);_
    * Serial.print(", ");*
    * }*
    * // End declaration*
    * Serial.print("};"); //*
    * // Comment*

* delay(1000);*

}
// This procedure sends a 38KHz pulse to the IRledPin for a certain # of microseconds.
void pulseIR(long microsecs) {

* cli(); // Turn off any background interrupts*

* while (microsecs > 0) {*
* // 38 kHz is about 13 microseconds high and 13 microseconds low*
* digitalWrite(IRledPin, HIGH); // 3 microseconds*
_ delayMicroseconds(10); /* hang out for 10 microseconds,
you can also change this to 9 if its not working /_
_
digitalWrite(IRledPin, LOW); // 3 microseconds*_
_ delayMicroseconds(10); /* hang out for 10 microseconds,
you can also change this to 9 if its not working */_

* // So 26 microseconds altogether*
* microsecs -= 26;*
* }*

* sei(); // Turn them back on*
}

void SendIRCode() {
* Serial.print(" irsend.sendRaw ({");*

* for (uint8_t i = 0; i < sendpulse; i++) {*

* if (i != 0){*
delayMicroseconds(pulses_[0] * RESOLUTION);
Serial.print(pulses[0] * RESOLUTION);
* Serial.print(", ");
}*_

pulseIR(pulses_[1] * RESOLUTION);
Serial.print(pulses[1] * RESOLUTION);
* Serial.print(", ");
}
// End declaration*

* Serial.print("},");
Serial.print((sendpulse 2)-1, DEC);
Serial.print(",38);//");_

}

can you guys help me to fix what is wrong from this sketch so it does not work

There are lots of changes we could make to the sketch to make it not work. How would you like it to not work?

If the "not" did not belong in the question, you are going to have to post your code CORRECTLY and tell us what the code actually does (and what hardware you are using and how it is connected to the Arduino) and how that differs from what you want.