wildbill:
You're going to have to combine the two sketches. Grumpy_Mike has a tutorial on the subject.
There are some pre-changes you can make to simplify the combination process though. As I said, you will need an ac object for each air conditioner and they will need different names, which they currently don't.
I suggest you pick one of your programs, take a copy of it and rename the ac object to something that includes the AC device's name. When you compile it you will get a lot of errors but they'll be easy to fix.
Then rename loop to something that tells you which AC unit it controls. Make a new loop that just calls the renamed function.
Do the same to the other program.
Then you can use Mike's tutorial to make a new program that combines the other two.
Thank you so much
here is my combined code, is this what you mean? it worked
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Hitachi.h>
#include <ir_Daikin.h>
const uint16_t kIrLed = 4; // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRHitachiAc ac(kIrLed); // Set the GPIO to be used for sending messages.
const int b1= 5; //D1
int power = 0;// 0---off 1---on
int y=1;
void printHitachiState() {
// Display the settings.
Serial.println("Hitachi A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
// Display the encoded IR sequence.
unsigned char* ir_code = ac.getRaw();
Serial.print("IR Code: 0x");
for (uint8_t i = 0; i < kHitachiAcStateLength; i++)
Serial.printf("%02X", ir_code[i]);
Serial.println();
}
void printDaikinState() {
// Display the settings.
Serial.println("Daikin A/C remote is in the following state:");
Serial.printf(" %s\n", ac.toString().c_str());
// Display the encoded IR sequence.
unsigned char* ir_code = ac.getRaw();
Serial.print("IR Code: 0x");
for (uint8_t i = 0; i < kDaikinStateLength; i++)
Serial.printf("%02X", ir_code[i]);
Serial.println();
}
void setup() {
pinMode(b1,INPUT); //Press ---1 not pressing---0
ac.begin();
Serial.begin(115200);
delay(200);
}
// Now send the IR signal.
void SendHitachi(){
#if SEND_HITACHI_AC
Serial.println("Sending IR command to A/C ...");
ac.send();
#endif
printHitachiState();
delay(5000);
}
void SendDaikin(){
#if SEND_DAIKIN
Serial.println("Sending IR command to A/C ...");
ac.send();
#endif
printDaikinState();
delay(5000);
}
void HitachiLoop() {
if (digitalRead(b1)==HIGH && power == 1){// its on alredy
ac.off();
ac.setFan(1);
ac.setMode(kHitachiAcCool);
ac.setTemp(23);
power = 0;
SendHitachi();
delay(1000);
}
else if (digitalRead(b1)==HIGH && power == 0){
ac.on();
ac.setFan(3);
ac.setMode(kHitachiAcCool);
ac.setTemp(20);
power = 1;
SendHitachi();
delay(1000);
}
}
void DaikinLoop() {
if (digitalRead(b1)==HIGH && power == 1){// its on alredy
ac.off();
ac.setFan(3);
ac.setMode(kDaikinCool);// why are the mode, fan , temp all needed here ???
ac.setTemp(23);
power = 0;
SendDaikin();
delay(1000);
}
else if (digitalRead(b1)==HIGH && power == 0){
ac.on();
ac.setFan(3);
ac.setMode(kDaikinCool);
ac.setTemp(23);
power = 1;
SendDaikin();
delay(1000);
}
}
void loop(){
if ( y==2 )
{
DaikinLoop();
}
else
{
HitachiLoop();
}
}
you can see here
void loop(){
if ( y==2 )
{
DaikinLoop();
}
else
{
HitachiLoop();
}
the if condition to choose whose code to run is only an integer, so it's obviously not desired, I'm merely using this to see if the other part of the code is working
so im still having trouble to figure out the if condition, aka, how to pair your universal ac remote to you desired AC, namely, namely, how to program for this process https://www.youtube.com/watch?v=I7hemzOwQig&t=175s