-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiotool_attiny13a_morse.h
109 lines (103 loc) · 4.45 KB
/
iotool_attiny13a_morse.h
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Output data by morse code for ATtiny13a at Arduino IDE 1.6.x
// I use the erdatsai's app "Morse Code Agent" to decode light.
// https://github.com/iotool/IOTool_ATtiny13a_LowLevel
//
// 2018-04-03 RoHa v1.0
// 2018-09-29 RoHa v1.1 PWM on/off
#include "iotool_attiny13a_lowlevel.h"
// morse 12 words per minute = 100/200/300ms
// morse 4 words per minute = 300/600/900ms
// morse f words per minute = 150/500/1000ms
// morse f words per minute = 400/1200/2400ms
#define ATTINY13A_MORSE
#define DELAY_MORSE _delay_ms(200)
#define DELAY_MORSE_2 _delay_ms(400)
#define DELAY_MORSE_3 _delay_ms(600)
void morseDigit(byte digit)
{
uint16_t mc = 15391; // 11110000011111
mc = mc >> digit;
#ifdef ATTINY13A_MORSE_PWM
PWM_ON; DELAY_MORSE; if (mc & 16) DELAY_MORSE; PWM_OFF; DELAY_MORSE;
PWM_ON; DELAY_MORSE; if (mc & 8) DELAY_MORSE; PWM_OFF; DELAY_MORSE;
PWM_ON; DELAY_MORSE; if (mc & 4) DELAY_MORSE; PWM_OFF; DELAY_MORSE;
PWM_ON; DELAY_MORSE; if (mc & 2) DELAY_MORSE; PWM_OFF; DELAY_MORSE;
PWM_ON; DELAY_MORSE; if (mc & 1) DELAY_MORSE; PWM_OFF; DELAY_MORSE_3;
#endif
#ifdef ATTINY13A_MORSE_PIN0
DIGITALWRITE_PB0_HIGH; DELAY_MORSE; if (mc & 16) DELAY_MORSE; DIGITALWRITE_PB0_LOW; DELAY_MORSE;
DIGITALWRITE_PB0_HIGH; DELAY_MORSE; if (mc & 8) DELAY_MORSE; DIGITALWRITE_PB0_LOW; DELAY_MORSE;
DIGITALWRITE_PB0_HIGH; DELAY_MORSE; if (mc & 4) DELAY_MORSE; DIGITALWRITE_PB0_LOW; DELAY_MORSE;
DIGITALWRITE_PB0_HIGH; DELAY_MORSE; if (mc & 2) DELAY_MORSE; DIGITALWRITE_PB0_LOW; DELAY_MORSE;
DIGITALWRITE_PB0_HIGH; DELAY_MORSE; if (mc & 1) DELAY_MORSE; DIGITALWRITE_PB0_LOW; DELAY_MORSE_3;
#endif
#ifdef ATTINY13A_MORSE_PIN1
DIGITALWRITE_PB1_HIGH; DELAY_MORSE; if (mc & 16) DELAY_MORSE; DIGITALWRITE_PB1_LOW; DELAY_MORSE;
DIGITALWRITE_PB1_HIGH; DELAY_MORSE; if (mc & 8) DELAY_MORSE; DIGITALWRITE_PB1_LOW; DELAY_MORSE;
DIGITALWRITE_PB1_HIGH; DELAY_MORSE; if (mc & 4) DELAY_MORSE; DIGITALWRITE_PB1_LOW; DELAY_MORSE;
DIGITALWRITE_PB1_HIGH; DELAY_MORSE; if (mc & 2) DELAY_MORSE; DIGITALWRITE_PB1_LOW; DELAY_MORSE;
DIGITALWRITE_PB1_HIGH; DELAY_MORSE; if (mc & 1) DELAY_MORSE; DIGITALWRITE_PB1_LOW; DELAY_MORSE_3;
#endif
#ifdef ATTINY13A_MORSE_PIN2
DIGITALWRITE_PB2_HIGH; DELAY_MORSE; if (mc & 16) DELAY_MORSE; DIGITALWRITE_PB2_LOW; DELAY_MORSE;
DIGITALWRITE_PB2_HIGH; DELAY_MORSE; if (mc & 8) DELAY_MORSE; DIGITALWRITE_PB2_LOW; DELAY_MORSE;
DIGITALWRITE_PB2_HIGH; DELAY_MORSE; if (mc & 4) DELAY_MORSE; DIGITALWRITE_PB2_LOW; DELAY_MORSE;
DIGITALWRITE_PB2_HIGH; DELAY_MORSE; if (mc & 2) DELAY_MORSE; DIGITALWRITE_PB2_LOW; DELAY_MORSE;
DIGITALWRITE_PB2_HIGH; DELAY_MORSE; if (mc & 1) DELAY_MORSE; DIGITALWRITE_PB2_LOW; DELAY_MORSE_3;
#endif
#ifdef ATTINY13A_MORSE_PIN3
DIGITALWRITE_PB3_HIGH; DELAY_MORSE; if (mc & 16) DELAY_MORSE; DIGITALWRITE_PB3_LOW; DELAY_MORSE;
DIGITALWRITE_PB3_HIGH; DELAY_MORSE; if (mc & 8) DELAY_MORSE; DIGITALWRITE_PB3_LOW; DELAY_MORSE;
DIGITALWRITE_PB3_HIGH; DELAY_MORSE; if (mc & 4) DELAY_MORSE; DIGITALWRITE_PB3_LOW; DELAY_MORSE;
DIGITALWRITE_PB3_HIGH; DELAY_MORSE; if (mc & 2) DELAY_MORSE; DIGITALWRITE_PB3_LOW; DELAY_MORSE;
DIGITALWRITE_PB3_HIGH; DELAY_MORSE; if (mc & 1) DELAY_MORSE; DIGITALWRITE_PB3_LOW; DELAY_MORSE_3;
#endif
#ifdef ATTINY13A_MORSE_PIN4
DIGITALWRITE_PB4_HIGH; DELAY_MORSE; if (mc & 16) DELAY_MORSE; DIGITALWRITE_PB4_LOW; DELAY_MORSE;
DIGITALWRITE_PB4_HIGH; DELAY_MORSE; if (mc & 8) DELAY_MORSE; DIGITALWRITE_PB4_LOW; DELAY_MORSE;
DIGITALWRITE_PB4_HIGH; DELAY_MORSE; if (mc & 4) DELAY_MORSE; DIGITALWRITE_PB4_LOW; DELAY_MORSE;
DIGITALWRITE_PB4_HIGH; DELAY_MORSE; if (mc & 2) DELAY_MORSE; DIGITALWRITE_PB4_LOW; DELAY_MORSE;
DIGITALWRITE_PB4_HIGH; DELAY_MORSE; if (mc & 1) DELAY_MORSE; DIGITALWRITE_PB4_LOW; DELAY_MORSE_3;
#endif
}
void morseValue(uint16_t value)
{
#ifdef ATTINY13A_MORSE_DIGIT_5
byte morse_10000 = 0;
#endif
byte morse_1000 = 0;
byte morse_100 = 0;
byte morse_10 = 0;
byte morse_1 = 0;
#ifdef ATTINY13A_MORSE_DIGIT_5
while(value >= 10000)
{
morse_10000++;
value-=10000;
}
#endif
while(value >= 1000)
{
morse_1000++;
value-=1000;
}
while(value >= 100)
{
morse_100++;
value-=100;
}
while(value >= 10)
{
morse_10++;
value-=10;
}
morse_1 = value;
#ifdef ATTINY13A_MORSE_DIGIT_5
morseDigit(morse_10000);
#endif
morseDigit(morse_1000);
morseDigit(morse_100);
morseDigit(morse_10);
morseDigit(morse_1);
DELAY_MORSE_3;
}