I recently posted a request, but attached the wrong sketch and cannot delete it. So here I go again...
I have a remote control which I want to send to the Arduino to facilitate a 30 minute sleep timer.
When the Arduino receives the correct code, I want to initiate the timer, light an LED to show that the code was received. When the time expires, the arduino is to send a code to turn off my Samsung TV and turn off my Receiver (Amp).
I was able to get the receive portion working using the example "rawRecv", and I was able to send the code using "rawSend".
However, I'm having trouble merging the two programs to work together. I believe it has to do with turning the Receive and Send functions on and off, as I read that it has to be programmed to do that, but no example was given. Below is my current sketch.
Any assistance would be appreciated, Thanks
/* ATTEMPTING TO MERGE rawSend.ino with rawRecev.ino to capture my remote "SLEEP" button, provide timed delay and shut off TV and AMP.
rawSend.ino Example sketch for IRLib2 MY PROGRAM rawSend_examp_me2_with_amp_THIRD_test.ino
Illustrates how to send a code Using raw timings which were captured
from the "rawRecv.ino" sample sketch. Load that sketch and
capture the values. They will print in the serial monitor. Then you
cut and paste that output into the appropriate section below.
* *************THIS SHUTS OFF MY TV AND AMP. BUT "NOTE" IR LED NEEDS TO BE NEAR AMP TO WORK-
************** WILL INSTALL 2ND IR LED IN SERIES AND REDUCE RESISTOR VALUE
*/
#include <IRLibSendBase.h> //We need the base code
#include <IRLib_HashRaw.h> //Only use raw sender
#include <IRLibRecvPCI.h> // Included for receiving SLEEP raw code (0xD5A)
IRrecvPCI myReceiver(2); // Pin number for receive pin
IRsendRaw mySender;
const int LedPin = 13;
void setup() {
Serial.begin(9600);
delay(2000); while (!Serial); //delay for Leonardo
pinMode(LedPin, OUTPUT);
myReceiver.enableIRIn(); //Start the receiver
}
/* Cut and paste the output from "rawRecv.ino" below here. It will
consist of a #define RAW_DATA_LEN statement and an array definition
beginning with "uint16_t rawData[RAW_DATA_LEN]= {…" and concludes
with "…,1000};"
*/
// Raw data from TV Power Off
#define RAW_DATA_LEN 68
uint16_t Tv_Pwr[RAW_DATA_LEN] = {
4470, 4530, 554, 1686, 550, 1686, 546, 1690,
558, 574, 550, 582, 546, 586, 554, 578,
550, 582, 554, 1682, 554, 1686, 550, 1686,
546, 586, 554, 578, 550, 582, 554, 578,
550, 582, 546, 586, 550, 1686, 550, 582,
546, 586, 550, 582, 546, 586, 554, 578,
550, 582, 546, 1690, 554, 578, 550, 1686,
546, 1690, 558, 1682, 550, 1686, 550, 1686,
546, 1694, 554, 1000
};
// Raw data from amp
#define RAW_DATA_LEN2 32 // added 2 AFTER RAW_DATA_LEN
uint16_t Amp_Pwr[RAW_DATA_LEN2] = {
878, 906, 1778, 1798, 1774, 902, 882, 906,
878, 906, 878, 4398, 874, 910, 886, 1794,
882, 902, 1778, 902, 886, 902, 882, 902,
882, 906, 882, 902, 882, 1798, 1774, 1000
};
// Raw data from the remote "SLEEP" button
#define RAW_DATA_LEN 32
uint16_t urcData[RAW_DATA_LEN] = {
2350, 594, 606, 586, 1178, 590, 610, 586,
1178, 594, 1178, 590, 602, 594, 1178, 590,
602, 594, 1178, 590, 602, 594, 1178, 590,
1174, 594, 606, 590, 602, 594, 606, 1000
};
/*
Cut-and-paste into the area above.
*/
void loop() {
if (myReceiver.getResults() == urcData) {
digitalWrite(LedPin, HIGH); // Turn on red LED during timing
delay(5000); //Temporary value to set sleep time. Could use millis, but no other actions are performed in sketch
mySender.send(Tv_Pwr, RAW_DATA_LEN, 38); //Pass the buffer,length, optionally frequency changed 36 to 38
delay(20);
mySender.send(Amp_Pwr, RAW_DATA_LEN2, 32);
digitalWrite(LedPin, LOW); // Turn off red LED after timed out
myReceiver.enableIRIn(); // Restart receiver
}
}