Here is the code, I want everytime I press the button it fires the signal
// This sketch will send out an arbitrary IR signal
int IRledPin = 13; // LED connected to digital pin 13
const int pulses = 37;
const int buttonPin = 2; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
const int IRsignal[pulses*2] = { // ON, OFF (in 10's of microseconds)
86, 88,
176, 88,
84, 90,
86, 88,
86, 88,
84, 90,
84, 94,
82, 88,
84, 174,
84, 90,
176, 88,
86, 2394,
86, 88,
176, 88,
86, 92,
88, 82,
92, 82,
86, 88,
86, 88,
92, 82,
92, 166,
92, 82,
182, 82,
86, 2398,
88, 82,
182, 82,
86, 88,
86, 88,
92, 82,
92, 86,
82, 84,
96, 82,
86, 172,
92, 82,
182, 86,
82, 0};
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the IR digital pin as an output:
pinMode(IRledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
SendCode(pulses, IRsignal);
}
}
// This procedure sends a 38KHz (26 microsecond cycle time) pulse to the IRledPin
// for a certain # of microseconds. We'll use this whenever we need to send codes
void pulseIR(long microsecs) {
// we'll count down from the number of microseconds we are told to wait
cli(); // this turns off any background interrupts
while (microsecs > 0) {
// 38 kHz is about 13 microseconds high and 13 microseconds low
digitalWrite(IRledPin, HIGH); // this takes about 3 microseconds to happen
delayMicroseconds(10); // hang out for 10 microseconds
digitalWrite(IRledPin, LOW); // this also takes about 3 microseconds
delayMicroseconds(10); // hang out for 10 microseconds
// so 26 microseconds altogether
microsecs -= 26;
}
sei(); // this turns them back on
}
void SendCode(const int pulses, const int IRsigna[]) {
for (int i=0; i< pulses; i++)
{
pulseIR(IRsignal[2*i] * 10);
delayMicroseconds(IRsignal[2*i+1] * 10);
}
}