Hi all,
Is anybody willing to help me in converting this Arduino code to C# ?
(i don’t need the Serial.print statements)
I know this should be using OutputCompare, but I have no clue how to construct the timingsBuffer from the code below.
#define SENDER 12
#define LED 13
int state = LOW;
const int rfdelay = 345;
const int rf_repeat = 3;
char onCommand[3] = "0F";
char offCommand[3] = "F0";
char Systemcode[6] = "0FFFF";
char Unit[6] = "0FFFF";
char* completeCode="123456789012";
void setup()
{
pinMode( LED, OUTPUT );
Serial.begin(9600);
Serial.println("Running");
}
void loop()
{
state = !state;
if (state == HIGH)
{
digitalWrite(LED, HIGH);
Serial.println("Sender ON");
completeCode[0]='\0';
strcat(completeCode, Systemcode);
strcat(completeCode, Unit);
strcat(completeCode, onCommand);
strcat(completeCode, '\0');
Serial.print("complete on code: ");
Serial.println( completeCode ); // prints 0FFFF0FFFF0F
}
else {
completeCode[0]='\0';
strcat(completeCode, Systemcode);
strcat(completeCode, Unit);
strcat(completeCode, offCommand);
strcat(completeCode, '\0');
Serial.print("complete off code: ");
Serial.println( completeCode ); // prints 0FFFF0FFFFF0
digitalWrite(LED, LOW);
digitalWrite(SENDER, LOW);
Serial.println("Sender OFF");
}
sendCodes( completeCode );
delay(10000);
}
void sendCodes( char* code )
{
char ch;
for (int i=1; i<=rf_repeat; i++)
{
for(int i2=0; i2<=11; i2++)
{
ch = code[i2];
switch(ch) {
case '0':
sendNull();
break;
case 'F':
sendFloat();
break;
case '1':
sendOne();
break;
}
}
sendSync();
}
}
void sender(int state)
{
digitalWrite( SENDER, state );
}
void wait()
{
delayMicroseconds(rfdelay);
}
void sendNull()
{
sender(1);
wait();
sender(0);
wait();
wait();
wait();
sender(1);
wait();
sender(0);
wait();
wait();
wait();
}
void sendFloat()
{
sender(1);
wait();
sender(0);
wait();
wait();
wait();
sender(1);
wait();
wait();
wait();
sender(0);
wait();
}
void sendOne()
{
sender(1);
wait();
sender(1);
wait();
sender(1);
wait();
sender(0);
wait();
sender(1);
wait();
sender(1);
wait();
sender(1);
wait();
sender(0);
wait();
}
void sendSync()
{
sender(1);
wait();
sender(0);
for (int w = 0; w < 31; w++)
{
wait();
}
}
Thanks,
Eric