-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanswers.c
157 lines (152 loc) · 4.11 KB
/
answers.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
/*******
Exercise 1: Basic movement to get familar with functions
-Move forward for 2 seconds
-Move backward for 2 seconds
-Move forward and turn left for 2 seconds
-Move forward and turn right for 2 seconds
*********/
//void control(){
// /****** Move forward for two seconds ******/
// /* Set direction of motor 1 and 2 */
// forward(1);
// forward(2);
// /* Set speed of motor 1 and 2 */
// setSpeed(1, 255);
// setSpeed(2, 255);
// /* Do nothing for 2 seconds. */
// delay(2000);
//
// /****** Move backward for two seconds ******/
// /* Set direction of motor 1 and 2 */
// backward(1);
// backward(2);
// /* Do nothing for 2 seconds. */
// delay(2000);
//
// /****** Move forward and turn left for 2 seconds ******/
// /* Turn both motors off */
// setSpeed(1, 0);
// setSpeed(2, 0);
// /* Set direction of motor 1 forward */
// forward(1);
// /* Turn motor 1 on (increase speed). */
// setSpeed(1, 255);
// /* Do nothing for 2 seconds. */
// delay(2000);
//
// /****** Move forward and turn right for 2 seconds ******/
// /* Turn both motors off */
// setSpeed(1, 0);
// setSpeed(2, 0);
// /* Set direction of motor 2 forward */
// forward(2);
// /* Turn motor 2 on (increase speed). */
// setSpeed(2, 255);
// /* Do nothing for 2 seconds. */
// delay(2000);
//
// /****** Stop ******/
// /* Turn both motors off */
// setSpeed(1, 0);
// setSpeed(2, 0);
// /* Do nothing for 4 seconds. */
// delay(4000);
//}
/*******
Exercise 2: Light-triggered robot.
-Moves forward if there is light
-(optional) Moves backward if light is blocked
*********/
//void control(){
// /* Turn both motors off */
// setSpeed(1, 0);
// setSpeed(2, 0);
//
// /****** Moves forward if there is light ******/
// /* If there is more light */
// if(moreLight()){
// /* Set direction of motor 1 and 2 */
// forward(1);
// forward(2);
// /* Set speed of motor 1 and 2 */
// setSpeed(1, 255);
// setSpeed(2, 255);
// }
// /****** Moves backward if light is blocked ******/
// if(lessLight()){
// /* Set direction of motor 1 and 2 */
// backward(1);
// backward(2);
// /* Set speed of motor 1 and 2 */
// setSpeed(1, 255);
// setSpeed(2, 255);
// }
//
// /* Wait 0.1s */
// delay(100);
//}
/*******
Exercise 3: Line follower: follows a line between the two sensors.
-Turn off motor 1 if line under sensor 1
-Turn off motor 2 if line under sensor 2
*********/
//void control(){
// /* Set direction of motor 1 and 2 */
// forward(1);
// forward(2);
//
// /****** Turn off motor 1 if line under sensor 1 ******/
// /* If sensor 1 is over a line */
// if(line(1)){
// /* Turn motor 1 off */
// setSpeed(1, 0);
// }
// else {
// /* Turn motor 1 on */
// setSpeed(1, 255);
// }
// /****** Turn off motor 2 if line under sensor 2 ******/
// /* If sensor 2 is over a line */
// if(line(2)){
// /* Turn motor 2 off */
// setSpeed(2, 0);
// }
// else {
// /* Turn motor 2 on */
// setSpeed(2, 255);
// }
//
// /* Wait 0.1s */
// delay(100);
//}
/*******
Exercise 4: Brightness control: fades LEDs using while loop
Requires wire from pin 3 to LED jumper in the top left corner
of PCB
*********/
//void control(){
// int brightness = 0;
//
// /* Write a while loop that counts up to 127
// While brightness is less than 127 */
// while(brightness < 127){
// /* analogWrite "brightness" to the LED */
// analogWrite(3, brightness);
// /* Add one to brightness */
// brightness++;
// /* Delay 10ms */
// delay(10);
// }
//
// /* Write a while loop that counts down to 0
// While brightness is greater than 0 */
// while(brightness > 0){
// /* analogWrite "brightness" to the LED */
// analogWrite(3, brightness);
// /* Subtract one from brightness */
// brightness--;
// /* Delay 10ms */
// delay(10);
// }
//
//}