summaryrefslogtreecommitdiff
path: root/trasmitter/arduino/sender.ino
blob: 93738750e7bc772f96032b0c607f073cfb2ef515 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const uint16_t pulseScale = 520// usec per sample unit 
 
// alternate HIGH and LOW, first one of each array is HIGH 
const uint8_t prologue[] = {
  1,11,11,11,11,11,1,
  2,31,12,21,11,12,1,
  1,11,11,21,11,11,1,
  1,11,1,
};
const size_t prologueSize = sizeof(prologue) / sizeof(uint8_t);
 
const uint8_t epilogue[] = {
  1,22,21,3// the last value doesn't much matter 
};
const size_t epilogueSize = sizeof(epilogue) / sizeof(uint8_t);
 
const uint8_t onSignal[] = {
  2,21,11,11,11,12,11,1,
};
const size_t onSize = sizeof(onSignal) / sizeof(uint8_t);
 
const uint8_t offSignal[] = {
  1,11,11,11,11,12,22,1,
};
const size_t offSize = sizeof(offSignal) / sizeof(uint8_t);
 
const int nTxPin = 7// Arduino digital pin you're using for radio data. 
 
void transmitArray(const uint8_t pulses[], size_t pulseCount) {
  for(size_t idx = 0; idx < pulseCount; idx+=2{
    digitalWrite(nTxPin, HIGH);
    delayMicroseconds(pulseScale*pulses[idx]);
 
    digitalWrite(nTxPin, LOW);
    delayMicroseconds(pulseScale*pulses[idx+1]);
  }
}
 
void transmitSignal(const uint8_t signal[], size_t signalSize) {
  transmitArray(prologue,prologueSize);
  transmitArray(signal,signalSize);
  transmitArray(epilogue,epilogueSize);
}
 
void sendTrain(const uint8_t signal[], size_t signalSize) {
  transmitSignal(signal,signalSize);
  delay(1000);
  transmitSignal(signal,signalSize);
  delay(2000);
  transmitSignal(signal,signalSize);
}
 
 
/**
 * The setup() function is called when a sketch starts. Used  to initialize
 * variables, pin modes, start using libraries, etc. The setup function will
 * only run once, after each powerup or reset of the Arduino board.
 */
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");
 
}
 
 
/**
 * The loop() function loops consecutively, allowing the program to change and
 * respond. Used to actively control the Arduino board.
 */
void loop()
{
  if (Serial.available() > 0)
  {
    int nIncomming = Serial.read();
    if (nIncomming == 49{ // char code for 1 
      Serial.println("ON");
      sendTrain(onSignal,onSize);
    }
 
    if (nIncomming == 48{ // char code for 0 
      Serial.println("OFF");
      sendTrain(offSignal,offSize);
    }
 
    Serial.println("Press 0 to turn off heating");
    Serial.println("Press 1 to turn on heating");
 }
}