-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.c
122 lines (89 loc) · 2.37 KB
/
functions.c
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
110
111
112
113
114
115
116
117
118
119
120
#include "functions.h"
IOPin_t LIGHT = { 5, &PINB };
IOPin_t MotorL_EN = { 1, &PINC };
IOPin_t MotorL_DIR = { 0, &PINC };
IOPin_t MotorR_EN = { 3, &PINC };
IOPin_t MotorR_DIR = { 2, &PINC };
void Fn_stop() {
SetPin(MotorR_EN, 0);
SetPin(MotorL_EN, 0);
SetPin(MotorR_DIR, 0);
SetPin(MotorL_DIR, 0);
}
void Fn_forward(uint8_t n) { // forward one robot length
for (; n; n--){
SetPin(MotorR_DIR, 0);
SetPin(MotorL_DIR, 1);
SetPin(MotorR_EN, 1);
SetPin(MotorL_EN, 1);
//Delay(2600000); // one rev
Delay(1290000);
SetPin(MotorR_EN, 0);
SetPin(MotorL_EN, 0);
}
}
void Fn_reverse(uint8_t n) { // back one robot length
for (; n; n--){
SetPin(MotorR_DIR, 1);
SetPin(MotorL_DIR, 0);
SetPin(MotorR_EN, 1);
SetPin(MotorL_EN, 1);
//Delay(2600000); // one rev
Delay(1290000);
SetPin(MotorR_EN, 0);
SetPin(MotorL_EN, 0);
}
}
void Fn_left(uint8_t n) { // turn 3 degrees left
for (; n; n--){
SetPin(MotorR_DIR, 0);
SetPin(MotorL_DIR, 0);
SetPin(MotorR_EN, 1);
SetPin(MotorL_EN, 1);
Delay(66667);
SetPin(MotorR_EN, 0);
SetPin(MotorL_EN, 0);
}
}
void Fn_right(uint8_t n) { // turn 3 degrees right
for (; n; n--){
SetPin(MotorR_DIR, 1);
SetPin(MotorL_DIR, 1);
SetPin(MotorR_EN, 1);
SetPin(MotorL_EN, 1);
Delay(66667);
SetPin(MotorR_EN, 0);
SetPin(MotorL_EN, 0);
}
}
void Fn_pause(uint8_t param) { // pause 1/10 of a second
Delay(225000*param);
}
void Fn_party(uint8_t param) { // aux fn 1
int melody[] = {
NOTE_FS5, NOTE_FS5, NOTE_D5, NOTE_B4, NOTE_B4, NOTE_E5,
NOTE_E5, NOTE_E5, NOTE_GS5, NOTE_GS5, NOTE_A5, NOTE_B5,
NOTE_A5, NOTE_A5, NOTE_A5, NOTE_E5, NOTE_D5, NOTE_FS5,
NOTE_FS5, NOTE_FS5, NOTE_E5, NOTE_E5, NOTE_FS5, NOTE_E5
};
int durations[] = {
8, 8, 8, 4, 4, 4,
4, 5, 8, 8, 8, 8,
8, 8, 8, 4, 4, 4,
4, 5, 8, 8, 8, 8
};
int thisNote;
int songLength = sizeof(melody)/sizeof(melody[0]);
for ( thisNote = 0; thisNote < songLength; thisNote++){
beep( melody[thisNote], durations[thisNote]*20);
}
}
void Fn_acc(uint8_t param) { // aux fn 2, acccessory activate
uint8_t i;
for( i = 0; i < 4; i++) {
SetPin(LIGHT, 1);
Delay(32768*4);
SetPin(LIGHT, 0);
Delay(32768*4);
}
}