/
transmitter.ino
72 lines (51 loc) · 1.48 KB
/
transmitter.ino
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
/*
RF transmitter example for attiny13.
The code was created by analyzing these sources:
1. RCSwitch library, https://code.google.com/p/rc-switch/
2. http://habrahabr.ru/post/224459/
3. http://avrbasiccode.wikispaces.com/
For data receving just use examples from RCSwitch.
Don't forget to set up properly frequency for attiny13.
See Arduino\hardware\attiny\boards.txt
I've used attiny13.build.f_cpu=1200000L to get proper delays
*/
#include <util/delay.h>
const short nPulseLength = 350;
const short nHighPulses_0 = (nPulseLength * 1);
const short nLowPulses_0 = (nPulseLength * 3);
const short nHighPulses_1 = (nPulseLength * 3);
const short nLowPulses_1 = (nPulseLength * 1);
const short nLowPulses_sync = (nPulseLength * 31);
#define PIN_TX (1<<PB3) // PB3 pin, goes to transmitter data pin
#define PIN_LED (1<<PB4) // PB4 pin, for led
void send(char* sCodeWord){
while (*sCodeWord != '\0') {
PORTB |= PIN_TX; // same as digitalWrite high
if(*sCodeWord == '0')
{
_delay_us(nHighPulses_0);
PORTB &= ~PIN_TX; // same as digitalWrite low
_delay_us(nLowPulses_0);
}else
{
_delay_us(nHighPulses_1);
PORTB &= ~PIN_TX;
_delay_us(nLowPulses_1);
}
++sCodeWord;
}
PORTB |= PIN_TX;
_delay_us(nHighPulses_0);
PORTB &= ~PIN_TX;
_delay_us(nLowPulses_sync);
}
void setup() {
DDRB |= PIN_TX; // Set output direction on PIN_TX
}
void loop() {
for(byte i = 0; i<10; ++i)
{
send("1011101000110101");
}
//_delay_ms(1000);
}