why do people on this forum have to be so passive aggressive?
no matter how much code i post it wont answer my question: "what are the limits of software serial compared to hardware serial?"
but seeing as people don't read unless it is in a little code window, here:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
#define TOPBIT 0x80000000
#define NEC_HDR_MARK 9000
#define NEC_HDR_SPACE 4500
#define NEC_BIT_MARK 560
#define NEC_ONE_SPACE 1600
#define NEC_ZERO_SPACE 560
#define NEC_RPT_SPACE 2250
int inByte = 0;
void setup()
{
DDRB = DDRB &~B00000100;
PORTB = PORTB &~B00000100;
mySerial.begin(9600);
}
void loop()
{
while (mySerial.available() > 1) { //removes lag, serial fills up and continues to repeat scommands even after serial input has stopped
mySerial.read();
}
if (mySerial.available() > 0) {
inByte = mySerial.read();
switch (inByte) {
case 99: //c
um_sendNEC(0xB54A9867, 32); //Wheel Clockwise
um_sendNEC(0xF50AFE01, 32); //Wheel Clockwise
break;
case 97: //a
um_sendNEC(0xB54A9867, 32); //Wheel Anticlockwise
um_sendNEC(0xF50A7E81, 32); //Wheel Anticlockwise
break;
case 98: //b
um_sendNEC(0xB54A9867, 32); //Centre Button
um_sendNEC(0xF50ABE41, 32); //Centre Button
break;
case 43: //+
um_sendNEC(0xB54A50AF, 32); //Vol Up
break;
case 45: //-
um_sendNEC(0xB54AD02F, 32); //Vol Down
break;
case 114: //r
um_sendNEC(0xB54A48B7, 32); //BAND
break;
case 116: //t
um_sendNEC(0xB54A30CF, 32); //ATT
break;
case 100: //d
um_sendNEC(0xB54A9867, 32); //DISP
um_sendNEC(0xF50AB649, 32); //DISP
break;
case 115: //s
um_sendNEC(0xB54A58A7, 32); //SRC
break;
case 101: //e
um_sendNEC(0xB54AD22D, 32); //EQ
break;
case 102: //f
um_sendNEC(0xB54A9867, 32); //DF
um_sendNEC(0xF50A16E9, 32); //DF
break;
case 117: //u
um_sendNEC(0xB54A02FD, 32); //Up
break;
case 111: //o
um_sendNEC(0xB54A827D, 32); //Down
break;
case 108: //l
um_sendNEC(0xB54A42BD, 32); //Left
break;
case 105: //i
um_sendNEC(0xB54AC23D, 32); //Right
break;
default:
inByte = 0;
}
// mySerial.write(inByte);
inByte = 0;
}
}
void um_sendNEC(unsigned long data, int nbits)
{
um_mark(NEC_HDR_MARK);
um_space(NEC_HDR_SPACE);
for (int i = 0; i < nbits; i++) {
if (data & TOPBIT) {
um_mark(NEC_BIT_MARK);
um_space(NEC_ONE_SPACE);
}
else {
um_mark(NEC_BIT_MARK);
um_space(NEC_ZERO_SPACE);
}
data <<= 1;
}
um_mark(NEC_BIT_MARK);
um_space(0);
}
void um_mark(int time) {
DDRB = DDRB | B00000100;
delayMicroseconds(time);
}
void um_space(int time) {
DDRB = DDRB &~B00000100;
delayMicroseconds(time);
}