summaryrefslogtreecommitdiff
path: root/trasmitter/sender.ino
blob: e53bd725c198278353f3df28a7e799dbbbffd9c9 (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
const uint16_t arrOn[] = {
  222222424223223222224222232342
};
const int nOnLen = sizeof(arrOn)/sizeof(uint16_t);
const uint16_t arrOff[] = {
  222222424223223222222222243342
};
const int nOffLen = sizeof(arrOff)/sizeof(uint16_t);
const int nTxPin = 7// Arduino digital pin you're using for radio data. 
const int pulseScale = 260// usec per sample unit 
 
 
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);
      // Widths are in units of 500us, for the full-period square wave 
      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);
}
 
 
/**
 * 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(arrOn, nOnLen);
    }
 
    if (nIncomming == 48{ // char code for 0 
      Serial.println("OFF");
      sendTrain(arrOff, nOffLen);
    }
 
    Serial.println("Press 0 to turn off heating");
    Serial.println("Press 1 to turn on heating");
 }
}