const uint16_t arrOn[] = {
2, 2, 2, 2, 2, 2, 4, 2, 4, 2, 2, 3, 2, 2, 3, 2, 2, 2, 2, 2, 4, 2, 2, 2, 2, 3, 2, 3, 4, 2,
};
const int nOnLen = sizeof(arrOn)/sizeof(uint16_t);
const uint16_t arrOff[] = {
2, 2, 2, 2, 2, 2, 4, 2, 4, 2, 2, 3, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 3, 3, 4, 2,
};
const int nOffLen = sizeof(arrOff)/sizeof(uint16_t);
const int nTxPin = 7;
const int pulseScale = 260;
void transmitArray(const uint16_t pulses[], int pulseCount) {
for (int repeat=0; repeat < 3; ++repeat) {
for(int pulse = 0; pulse < pulseCount; ++pulse) {
int pulseWidth = pulses[pulse];
digitalWrite(nTxPin, HIGH);
delayMicroseconds(pulseScale*pulseWidth);
digitalWrite(nTxPin, LOW);
delayMicroseconds(pulseScale*pulseWidth);
}
}
}
void sendTrain(const uint16_t pulses[], int pulseCount) {
transmitArray(pulses,pulseCount);
delay(1000);
transmitArray(pulses,pulseCount);
delay(2000);
transmitArray(pulses,pulseCount);
}
void setup()
{
pinMode(nTxPin, OUTPUT);
digitalWrite(nTxPin, LOW);
Serial.begin(9600);
Serial.println("Press 0 to turn off heating");
Serial.println("Press 1 to turn on heating");
}
void loop()
{
if (Serial.available() > 0)
{
int nIncomming = Serial.read();
if (nIncomming == 49) {
Serial.println("ON");
sendTrain(arrOn, nOnLen);
}
if (nIncomming == 48) {
Serial.println("OFF");
sendTrain(arrOff, nOffLen);
}
Serial.println("Press 0 to turn off heating");
Serial.println("Press 1 to turn on heating");
}
}