-
Notifications
You must be signed in to change notification settings - Fork 0
/
FinalCode.c
213 lines (201 loc) · 5.61 KB
/
FinalCode.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#pragma config(Sensor, in1, pot, sensorPotentiometer)
#pragma config(Motor, port2, RightMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port3, Arm, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port4, , tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port6, LeftMotor, tmotorServoContinuousRotation, openLoop)
#pragma config(Motor, port7, Claw, tmotorServoStandard, openLoop)
#pragma config(Motor, port8, Turntable, tmotorServoStandard, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
bool boolSlowButton = false;
bool clawclose=false;
bool clawopen=false;
bool clawc=false;
bool hum = false;
//Play the digdug theme :)
task digdug()
{
while(1)
{
// 225 = Tempo
// 5 = Default octave
// Quarter = Default note length
// 10% = Break between notes
//
playTone( 523, 12); wait1Msec( 133); // Note(C, Duration(Eighth))
playTone( 783, 12); wait1Msec( 133); // Note(G, Duration(Eighth))
playTone( 523, 12); wait1Msec( 133); // Note(C, Duration(Eighth))
playTone( 783, 12); wait1Msec( 133); // Note(G, Duration(Eighth))
playTone( 493, 12); wait1Msec( 133); // Note(B4, Duration(Eighth))
playTone( 783, 12); wait1Msec( 133); // Note(G, Duration(Eighth))
playTone( 493, 12); wait1Msec( 133); // Note(B4, Duration(Eighth))
playTone( 783, 12); wait1Msec( 133); // Note(G, Duration(Eighth))
playTone( 466, 12); wait1Msec( 133); // Note(A#4, Duration(Eighth))
playTone( 783, 12); wait1Msec( 133); // Note(G, Duration(Eighth))
playTone( 466, 12); wait1Msec( 133); // Note(A#4, Duration(Eighth))
playTone( 783, 12); wait1Msec( 133); // Note(G, Duration(Eighth))
playTone( 440, 12); wait1Msec( 133); // Note(A4, Duration(Eighth))
playTone( 783, 12); wait1Msec( 133); // Note(G, Duration(Eighth))
playTone( 440, 12); wait1Msec( 133); // Note(A4, Duration(Eighth))
playTone( 783, 12); wait1Msec( 133); // Note(G, Duration(Eighth))
playTone( 415, 12); wait1Msec( 133); // Note(G#4, Duration(Eighth))
playTone( 698, 12); wait1Msec( 133); // Note(F, Duration(Eighth))
playTone( 415, 12); wait1Msec( 133); // Note(G#4, Duration(Eighth))
playTone( 698, 12); wait1Msec( 133); // Note(F, Duration(Eighth))
playTone( 415, 12); wait1Msec( 133); // Note(G#4, Duration(Eighth))
playTone( 698, 12); wait1Msec( 133); // Note(F, Duration(Eighth))
playTone( 415, 12); wait1Msec( 133); // Note(G#4, Duration(Eighth))
playTone( 698, 12); wait1Msec( 133); // Note(F, Duration(Eighth))
playTone( 391, 12); wait1Msec( 133); // Note(G4, Duration(Eighth))
playTone( 698, 12); wait1Msec( 133); // Note(F, Duration(Eighth))
playTone( 391, 12); wait1Msec( 133); // Note(G4, Duration(Eighth))
playTone( 698, 12); wait1Msec( 133); // Note(F, Duration(Eighth))
playTone( 440, 12); wait1Msec( 133); // Note(A4, Duration(Eighth))
playTone( 698, 12); wait1Msec( 133); // Note(F, Duration(Eighth))
playTone( 493, 12); wait1Msec( 133); // Note(B4, Duration(Eighth))
}
}
void armprogram()
{
if (vexRT[Btn6U] == 1 )
{
motor[Arm]=127;
hum = true;
}
else
{
motor[Arm]=0;
}
if (vexRT[Btn6D] == 1 )
{
hum = true;
motor[Arm]=-127;
}
else
{
motor[Arm]=0;
}
}
void get_controls()
{
if (vexRT[Btn6D] == 1)
{
clawclose = true;
clawopen=false;
}
else
{
clawclose = false;
clawopen = true;
}
if (vexRT[Btn6U] == 1)
{
clawopen = true;
}
else
{
clawopen = false;
}
if (vexRT[Btn7L] == 1)
{
clawc = true;
}
else
{
clawc = false;
}
if (clawc == false)
{
motor[Turntable]=-127;
}
else
{
motor[Turntable]=127;
}
if (clawopen == true)
{
motor[Claw]=127;
clawclose=false;
}
else if (clawclose == true)
{
motor[Claw]=-127;
clawopen=false;
}
else
{
motor[Claw]=0;
}
}
//Slow down the controls if a button is pressed
void SlowButton()
{
if(vexRT(Btn8D) == true)
{
boolSlowButton = true;
}
if(vexRT(Btn8U) == true)
{
boolSlowButton = false;
}
}
//this code is also called tank drive. One joystick controls 1 side of the robot base.
void StandardDrive()
{
if(boolSlowButton == true)
{
motor[RightMotor] = vexRT(Ch2)/3;
motor[LeftMotor] = vexRT(Ch3)/3;
}
else
{
motor[RightMotor] = vexRT(Ch2);
motor[LeftMotor] = vexRT(Ch3);
}
}
//we dont need this code, but ill keep it here so if it's needed its here :)
// This code has 1 stick for up and down, as well as turning.
/*void ArcadeDrive1Stick()
{
motor[LeftMotor] = (vexRT[Ch2] + vexRT[Ch1])/2; // (y + x)/2
motor[RightMotor] = (vexRT[Ch2] - vexRT[Ch1])/2; // (y - x)/2
}
*/
// This code has 1 stick for up and down, and the other for turning.
void ArcadeDrive2Stick()
{
if(boolSlowButton == true)
{
motor[LeftMotor] = (vexRT[Ch3] + vexRT[Ch1])/3; // (y + x)/3
motor[RightMotor] = (vexRT[Ch3] - vexRT[Ch1])/3; // (y - x)/3
}
else
{
motor[LeftMotor] = (vexRT[Ch3] + vexRT[Ch1]); // (y + x)
motor[RightMotor] = (vexRT[Ch3] - vexRT[Ch1]); // (y - x)
}
}
// if pot < 2047, run arcade controls, else run standard drive (tank controls)
void Base()
{
if(SensorValue[pot] < 2047)
{
ArcadeDrive2Stick();
}
else
{
StandardDrive();
}
}
//instructions: if the potentiometer is less than halfway, use arcade drive. If it's over halfway, use tank drive.
task main()
{
startTask(digdug);
bool boolReitzigSanity = false; //this is always false, as Mr. Reitzig is insane :p
while(boolReitzigSanity == false) // run forever
{
SlowButton();
Base();
get_controls();
armprogram();
}
}