-
Notifications
You must be signed in to change notification settings - Fork 0
/
gloveV1.0.ino
67 lines (55 loc) · 1.49 KB
/
gloveV1.0.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
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void swap(int& a, int& b) {
int t = a;
a = b;
b = t;
}
void shuffle(int* array, int n) {
while (n--) {
swap(array[random(n+1)], array[n]);
}
}
void loop() {
int array[] = { 6,7,8,9 };
/* using digital pins 6-9 for the 4 fingers of each hand.
*/
shuffle(array, 4); //shuffles the array randomly
/* Serial.print(array[0]); Serial.print(array[1]); Serial.print(array[2]); Serial.print(array[3]);
Serial.println("\n");
Tone needs 2 arguments, but can take three
1) Pin#
2) Frequency - this is in hertz (cycles per second) which determines the pitch of the noise made
3) Duration - how long the tone plays
*/
// vibrates each of the 4 fingers on each hand once per cycle.
tone(array[0], 250, 100);
delay(160);
tone(array[1], 250, 100);
delay(160);
tone(array[2], 250, 100);
delay(160);
tone(array[3], 250, 100);
delay(160);
shuffle(array, 4); //shuffles the array randomly
tone(array[0], 250, 100);
delay(160);
tone(array[1], 250, 100);
delay(160);
tone(array[2], 250, 100);
delay(160);
tone(array[3], 250, 100);
delay(160);
shuffle(array, 4); //shuffles the array randomly
tone(array[0], 250, 100);
delay(160);
tone(array[1], 250, 100);
delay(160);
tone(array[2], 250, 100);
delay(160);
tone(array[3], 250, 100);
delay(160);
delay(1280) // this is the "2 off cycle". The vibrating pattern is "3 on 2 off".
}