So Im trying to make a remote IR blaster for my AC but when I flash the code via the web IDE the core flashes green then red and doesnt connect. Is it running out of RAM or flash, how would I optimize this code?
/* FIRMWARE */
#include "IRSend.h"
// IR Code Settings
const int IR_LED_PIN = 7;
const int MESSAGE_LENGTH = 68;
const int IR_FREQ = 38; // In kHz
// Create an instance of the IR remote
IRSend IRremote = IRSend(IR_LED_PIN);
// IR Codes for LG window AC
unsigned int pwrCmd[MESSAGE_LENGTH] = {
8700, 4280, 620, 1540, 600, 480, 600, 480, 600, 480, 600, 480, 600, 460, 620, 460, 620, 1540, 600, 480, 600, 1560, 600, 1560, 600, 460, 620, 460, 620, 1540, 620, 1540, 600, 480, 600, 1560, 600, 480, 600, 480, 600, 480, 600, 460, 600, 480, 600, 480,600, 1560, 600, 480, 600, 1540, 620, 1560, 580, 1560, 600, 1560, 600, 1560, 600, 1560, 600, 480, 600, 0 };
unsigned int tmpDownCmd[MESSAGE_LENGTH] = {
8700, 4280, 600, 1560, 600, 480, 600, 480, 600, 480, 600, 480, 600, 460, 600, 480, 600, 1560, 600, 480, 600, 1560, 600, 1560, 600, 460, 620, 460, 600, 1560, 600, 1560, 600, 480, 600, 480, 600, 1540, 620, 460, 620, 1540, 600, 480, 600, 480, 600, 480, 600, 1560, 600, 1540, 620, 460, 600, 1560, 600, 480, 600, 1560, 600, 1560, 600, 1560, 600, 460, 620, 0 };
unsigned int tmpUpCmd[MESSAGE_LENGTH] = {
8700, 4300, 600, 1560, 600, 460, 600, 480, 600, 480, 580, 500, 600, 480, 600, 480, 580, 1560, 580, 500, 600, 1560, 600, 1560, 600, 480, 600, 480, 560, 1600, 600, 1540, 600, 480, 600, 1560, 580, 500, 600, 1560, 600, 480, 600, 480, 580, 500, 560, 500, 580, 1580, 600, 480, 600, 1560, 600, 480, 580, 1580, 580, 1580, 580, 1560, 600, 1560, 600, 480, 600, 0 };
unsigned int fanCmd[MESSAGE_LENGTH] = {
8700, 4280, 620, 1540, 620, 460, 600, 480, 600, 480, 600, 480, 600, 480, 600, 480, 580, 1560, 600, 480, 600, 1560, 600, 1560, 600, 480, 600, 480, 580, 1560, 620, 1540, 600, 480, 600, 1560, 600, 480, 600, 480, 580, 1580, 600, 1560, 580, 480, 600, 480, 600, 1560, 600, 480, 600, 1560, 600, 1560, 580, 480, 600, 480, 600, 1560, 600, 1560, 600, 480, 600, 0 };
unsigned int tmrCmd[MESSAGE_LENGTH] = {
8660, 4320, 600, 1560, 600, 460, 600, 480, 600, 480, 600, 480, 600, 480, 600, 480, 580, 1580, 580, 480, 600, 1560, 600, 1560, 600, 480, 600, 480, 600, 1560, 580, 1580, 580, 480, 600, 1560, 600, 1560, 600, 1560, 600, 1560, 600, 1560, 600, 480, 580, 480, 600, 1560, 600, 480, 600, 480, 600, 480, 600, 480, 580, 480, 620, 1540, 600, 1560, 600, 480, 600, 0 };
unsigned int mdeCmd[MESSAGE_LENGTH] = {
8700, 4280, 600, 1560, 600, 480, 580, 500, 600, 480, 600, 480, 600, 460, 600, 480, 600, 1560, 600, 480, 600, 1560, 600, 1560, 560, 520, 560, 500, 600, 1560, 600, 1560, 560, 520, 580, 1580, 600, 1560, 600, 460, 580, 1580, 600, 1560, 600, 480, 600, 480, 560, 1600, 600, 480, 600, 460, 600, 1560, 580, 500, 600, 480, 600, 1560, 600, 1560, 560, 520, 580, 0 };
// REST Points
int ac(String command) {
unsigned int *irCode;
String substring = command.substring(0,3);
if(substring == "PWR") irCode = pwrCmd;
else if(substring == "FAN") irCode = fanCmd;
else if(substring == "TMR") irCode = tmrCmd;
else if(substring == "MDE") irCode = mdeCmd;
else if(substring == "TMP") {
if(command.substring(4) == "DOWN")
irCode = tmpDownCmd;
else if(command.substring(4) == "UP")
irCode = tmpUpCmd;
else
return -2;
}
else return -1;
// Send IR command
IRremote.sendRaw(irCode, MESSAGE_LENGTH, IR_FREQ);
return 1;
}
int tinkerDigitalWrite(String command)
{
bool value = 0;
//convert ascii to integer
int pinNumber = command.charAt(1) - '0';
//Sanity check to see if the pin numbers are within limits
if (pinNumber< 0 || pinNumber >7) return pinNumber;
if(command.substring(3,7) == "HIGH") value = 1;
else if(command.substring(3,6) == "LOW") value = 0;
else return -2;
if(command.startsWith("D"))
{
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, value);
return 1;
}
else if(command.startsWith("A"))
{
pinMode(pinNumber+10, OUTPUT);
digitalWrite(pinNumber+10, value);
return 1;
}
else return -3;
}
/* FIRMWARE */
void setup()
{
Spark.function("digitalwrite", tinkerDigitalWrite);
Spark.function("ac", ac);
}
/* This function loops forever --------------------------------------------*/
void loop()
{
//This will run in a loop
}