Good Day I have written a program and everything is working as expected, the problem is I need to streamline the code as I am running out of space on the Arduino ethernet board. I need to add more functionality as well.I am relatively new to Arduino programing and I think my code can be shortened considerably.I would appreciate any suggestions in reducing the code.
I only posted the main sections of concern, because code wont fit in post
Many thanks
//UDP OUTPUT START
if (packBuff[0] == 'B' && packBuff[2] == 'O')
{
// READ BOARD NO
if (packBuff[1] == '1'){BoardNo = 1;Serial.print("B");Serial.print(BoardNo);}
else if (packBuff[1] == '2'){BoardNo = 2;Serial.print("B");Serial.print(BoardNo);}
else if (packBuff[1] == '3'){BoardNo = 3;Serial.print("B");Serial.print(BoardNo);}
else if (packBuff[1] =='4'){BoardNo = 4;Serial.print("B");Serial.print(BoardNo);}
// READ PIN NO
if (packBuff[3] == '1'){PinNo = 1;Serial.print("0");Serial.print(PinNo);}
else if (packBuff[3] == '2'){PinNo = 2;Serial.print("0");Serial.print(PinNo);}
else if (packBuff[3] == '3'){PinNo = 3;Serial.print("0");Serial.print(PinNo);}
else if (packBuff[3] == '4'){PinNo = 4;Serial.print("0");Serial.print(PinNo);}
else if (packBuff[3] == '5'){PinNo = 5;Serial.print("0");Serial.print(PinNo);}
else if (packBuff[3] == '6'){PinNo = 6;Serial.print("0");Serial.print(PinNo);}
else if (packBuff[3] == '7'){PinNo = 7;Serial.print("0");Serial.print(PinNo);}
else if (packBuff[3] == '8'){PinNo = 8;Serial.print("0");Serial.print(PinNo);}
// SET PIN MODE
if (packBuff[4] == 'H'){pwmNo = 255; pwmLabel = 1; Serial.print("H");UdpOutput();}
else if (packBuff[4] == 'L'){pwmNo = 000; pwmLabel = 2; Serial.print("L");UdpOutput();}
else if (packBuff[4] == 'P'){pwmNo = pwmVal; pwmLabel = 3; Serial.print("P"); Serial.print(pwmNo); UdpOutput();}
}
// UDP OUTPUT END
//IDP IR TRIGER = IR01 - IR99
if (packBuff[0] == 'I' && packBuff[1] == 'R')
{//Serial.print("IR");
// SER 1ST CARACTER 0 - 9
if (packBuff[2] == '0'){IR1 = 0;}
else if (packBuff[2] == '1'){IR1 = 1;}
else if (packBuff[2] == '2'){IR1 = 2;}
else if (packBuff[2] == '3'){IR1 = 3;}
else if (packBuff[2] == '4'){IR1 = 4;}
else if (packBuff[2] == '5'){IR1 = 5;}
else if (packBuff[2] == '6'){IR1 = 6;}
else if (packBuff[2] == '7'){IR1 = 7;}
else if (packBuff[2] == '8'){IR1 = 8;}
else if (packBuff[2] == '9'){IR1 = 9;}
// SER 2D CARACTER 0 - 9
if (packBuff[3] == '0'){IR2 = 0;}
else if (packBuff[3] == '1'){IR2 = 1;}
else if (packBuff[3] == '2'){IR2 = 2;}
else if (packBuff[3] == '3'){IR2 = 3;}
else if (packBuff[3] == '4'){IR2 = 4;}
else if (packBuff[3] == '5'){IR2 = 5;}
else if (packBuff[3] == '6'){IR2 = 6;}
else if (packBuff[3] == '7'){IR2 = 7;}
else if (packBuff[3] == '8'){IR2 = 8;}
else if (packBuff[3] == '9'){IR2 = 9;}
UdpIR();
}
void UdpOutput()
{
if (BoardNo == 1){ioNo = PinNo - 1 ;}
else if (BoardNo == 2){ioNo = PinNo + 7 ;}
else if (BoardNo == 3){ioNo = PinNo + 15 ;}
else if (BoardNo == 4){ioNo = PinNo + 23 ;}
// output code
ShiftPWM.SetOne(ioNo, pwmNo);
//stringMsg = "hello";
// Serial.print("Output Sent");//Serial.print(pwmlbl);//Write notification
Udp.beginPacket(iPhoneIP, iPhonePort);
Udp.write("Output Sent"); // Send Message back to iPhone
Udp.endPacket();
void inputprint()
{
if (inPut == 0 && instate == 0){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I1OP"); Udp.endPacket();}
delay(10);
if (inPut == 0 && instate == 1){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I1CL"); Udp.endPacket();}
delay(10);
if (inPut == 1 && instate == 0){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I2OP"); Udp.endPacket();}
delay(10);
if (inPut == 1 && instate == 1){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I2CL"); Udp.endPacket();}
delay(10);
if (inPut == 2 && instate == 0){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I3OP"); Udp.endPacket();}
delay(10);
if (inPut == 2 && instate == 1){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I3CL"); Udp.endPacket();}
delay(10);
if (inPut == 3 && instate == 0){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I4OP"); Udp.endPacket();}
delay(10);
if (inPut == 3 && instate == 1){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I4CL"); Udp.endPacket();}
delay(10);
if (inPut == 4 && instate == 0){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I5OP"); Udp.endPacket();}
delay(10);
if (inPut == 4 && instate == 1){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I5CL"); Udp.endPacket();}
delay(10);
if (inPut == 5 && instate == 0){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I6OP"); Udp.endPacket();}
delay(10);
if (inPut == 5 && instate == 1){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I6CL"); Udp.endPacket();}
delay(10);
if (inPut == 6 && instate == 0){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I7OP"); Udp.endPacket();}
delay(10);
if (inPut == 6 && instate == 1){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I7CL"); Udp.endPacket();}
delay(10);
if (inPut == 7 && instate == 0){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I8OP"); Udp.endPacket();}
delay(10);
if (inPut == 7 && instate == 1){Udp.beginPacket(iPhoneIP, iPhonePort); Udp.write("I8CL"); Udp.endPacket();}
}
if (IR1 == 0 && IR2 == 1){IR01();}
if (IR1 == 0 && IR2 == 2){IR02();}
if (IR1 == 0 && IR2 == 3){IR03();}
if (IR1 == 0 && IR2 == 4){IR04();}
if (IR1 == 0 && IR2 == 5){IR05();}
if (IR1 == 0 && IR2 == 6){IR06();}
if (IR1 == 0 && IR2 == 7){IR07();}
if (IR1 == 0 && IR2 == 8){IR08();}
}// 40 codes
void IR05(){cli();for (int i = 0; i < 1; i++) {irsend.sendRaw(raw1,100,38);delay(80);}sei();Udp.beginPacket(iPhoneIP, iPhonePort);Udp.write("IR05S");Udp.endPacket();Serial.write("IR05S");irrecv.enableIRIn();}//sinoteck TV ON/Off
void IR06(){cli();for (int i = 0; i < 1; i++) {irsend.sendRaw(raw1,100,38);delay(80);}sei();Udp.beginPacket(iPhoneIP, iPhonePort);Udp.write("IR06S");Udp.endPacket();Serial.write("IR06S");irrecv.enableIRIn();}//sinoteck TV ON/Off