-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFret testing.c
63 lines (47 loc) · 1.11 KB
/
Fret testing.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
const int STRUMMING_POWER = 20;
const int FRET_SPEED = -20;
const int TIME_UNIT = 2000;
const int FULL_ROTATION = 360;
const int FRET_CLICKS = 30;
const int FRET_TIMING = 1000;
void pluck(int direction)
{
motor[motorA] = direction * STRUMMING_POWER;
nMotorEncoder[motorA] = 0;
while(abs(nMotorEncoder[motorA]) < 90)
{}
motor[motorA] = 0;
}
void setAndPlayFret(int fret, int direction)
{
int clicksForFret = FRET_CLICKS * (fret - 1);
int clicksToRotate = FULL_ROTATION - clicksForFret;
motor[motorD] = FRET_SPEED;
while(abs(nMotorEncoder[motorD]) < clicksToRotate)
{}
motor[motorD] = 0;
pluck(direction);
wait1Msec(FRET_TIMING);
motor[motorD] = FRET_SPEED;
while(abs(nMotorEncoder[motorD]) < FULL_ROTATION)
{}
motor[motorD] = 0;
nMotorEncoder[motorD] = 0;
}
int playNotes(int *fret, int *hold, int length)
{
int direction = 1;
for(int note = 0; note < length; note++)
{
setAndPlayFret(fret[note], direction);
wait1Msec(hold[note]*TIME_UNIT);
direction *= -1;
}
return direction;
}
task main()
{
int fret[5] = {2, 3, 5, 7, 10};
int hold[5] = {1, 1, 1, 1, 1};
playNotes(fret, hold, 7);
}