# Converting IR signals to 1-9 digits

Hey Fellas

I am very new in this arduino community and I have been struggling on a project for a week I cannot get it work coz lack of programming skills I guess. I wants to receive IR signals and converts them to 0-9 digits according to each key pressed on IR remote And using 0-9 digits I wants to drive my servo. SO basically I would enter the angle ( example servo.write(180)) from my remote. Also angle values will vary from 0 to 180 degree. I cannot make a logic with C.

Kindly check my code and I know guys its messy and might be stupidly written but I would appreciate your kind help to get this idea done !! Thanks

``````#include <Servo.h>
#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
Servo myservo;
int servoPin = 9;
int EK=0;

#define EnterKey 1386468383
#define k1 2534850111
#define k2Â  1033561079
#define k3 1635910171
#define k4 2351064443
#define k5 1217346747
#define k6 71952287
#define k7 851901943
#define k8 465573243
#define k9 1053031451
#define Zero 3238126971
int i, j, k;
int digit;

void setup()
{
irrecv.enableIRIn();
myservo.attach(servoPin);
myservo.write(0);
Serial.begin(9600);

}

void loop()
{
do
{
if (irrecv.decode(&results))
{
i = conversion();
if (EK = EnterKey)
{
myservo.write(i);
irrecv.resume();

}
else if (i != NULL)
{
j = conversion();
if (EK = EnterKey)
{
myservo.write((i + 10) + j);
irrecv.resume();
Serial.println((i + 10) + j);

}
else if (i, j != NULL)
{
k = conversion();
if (EK = EnterKey)
{
myservo.write((i + 100) + (j + 10) + k);
irrecv.resume();

}
}

}

}
} while (0 <= i || (i + 10) + j || (i + 100) + (j + 10) + k <= 180);
Serial.println(digit);

}

int conversion()

{
switch (results.value)
{
case EnterKey:
EK = EnterKey;
break;
case k1:
digit = 1;
break;
case k2:
digit = 2;
break;
case k3:
digit = 3;
break;
case k4:
digit = 4;
break;
case k5:
digit = 5;
break;
case k6:
digit = 6;
break;
case k7:
digit = 7;
break;
case k8:
digit = 8;
break;
case k9:
digit = 9;
break;
case Zero:
digit = 0;
break;
default:
break;
}
return digit;

}
``````

jesus I asked such a hard question I guess

Jesus, you got a give people some time lol.

Please fix the "=" chars. A single = means assignment, a double == means comparison (equal).

And what's that
else if (i, j != NULL)

can yu guys help me to write a code to store values from IR remote and then use them to set angle of servo. I have done so far below code. I cannot think how to succeed further.

Thanks

``````#include <IRremote.h>
#include <Servo.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
Servo myservo;
int servoPin = 9;

#define EnterKey 1386468383
#define k1 2534850111
#define k2Â  1033561079
#define k3 1635910171
#define k4 2351064443
#define k5 1217346747
#define k6 71952287
#define k7 851901943
#define k8 465573243
#define k9 1053031451
#define Zero 3238126971
int digit;

void setup()
{
irrecv.enableIRIn();
myservo.attach(servoPin);
myservo.write(0);
Serial.begin(9600);

}

void loop()
{

if (irrecv.decode(&results))
{
unsigned long val2 = results.value;
int digits = conversion(val2);

if (digits != 400){

Serial.println(digits);
delay(200);
irrecv.resume();
}
else{
delay(100);
irrecv.resume();
}

}
}

int conversion(unsigned long IRval)
{
switch (IRval)
{
case EnterKey:
digit = 200;
break;
case k1:
digit = 1;
break;
case k2:
digit = 2;
break;
case k3:
digit = 3;
break;
case k4:
digit = 4;
break;
case k5:
digit = 5;
break;
case k6:
digit = 6;
break;
case k7:
digit = 7;
break;
case k8:
digit = 8;
break;
case k9:
digit = 9;
break;
case Zero:
digit = 0;
break;
default:
digit = 400;
break;
}

return digit;

}
``````