Hi all. I had the same problem. My robox irdirection not work on MEGA 2560.
Below solution :
"
#include <SoftwareSerial.h>
void setup()
{
Serial3.begin(9600); // output to PC or other device
Serial3.println("Running IR Fire detection...");
Serial2.begin(4800); // port connected to Robox IRDirection module
}
/*****************************************************************/
int fire(char num_diode)
{
int val,i;
char c[5];
Serial2.print(num_diode); // select diode on IrDiredtion module
while(1)
{
if(Serial2.read() == 10) //stop at begin of data
break;
}
for(i = 0; i < 5; i++)
{
while(1)
{
if(Serial2.available()) // wait to ready for transmit
break;
}
c = Serial2.read();
- }*
- val=0;*
- for(i = 0; i < 5; i++)*
- {*
if((c >= 48) && (c < 58)) // ASCII table 48 - "0" ... 57 -"9"
* {*
_ val = val * 10 + c - 48;
* }
else*
* return(val);
}
}
/***********************************************************************/
void loop()
{
int i,s;
for(i = 0; i < 7; i++)
{
s=fire(i);
Serial3.print(s);
Serial3.print(" ");
}
Serial3.println();
delay(1000);
}
"*_