forked from woodenclock/mBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.c
More file actions
120 lines (102 loc) · 1.62 KB
/
Copy pathcode.c
File metadata and controls
120 lines (102 loc) · 1.62 KB
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
/*
* mBot code for Group 3a2
*
* Members:
* Sungmin
* Kishor
* Svetha
* Alvin
*/
#include "MeMCore.h"
//define the required variables here
int motorspeed = 100;
MeDCMotor motor_right(M1);
MeDCMotor motor_left(M2);
//move forward
void forward()
{
motor_right.run(+motorSpeed);
motor_left.run(-motorSpeed);
}
//turn right
void right_turn()
{
motor_right.run(+motorSpeed);
motor_left.run(+motorSpeed);
}
//turn left
void left_turn()
{
motor_right.run(-motorSpeed);
motor_left.run(-motorSpeed);
}
//detect black strip
bool black_strip()
{
//stop
//play tune
//stop arduino from moving
}
//ultrasound(distance in front)
float dist_front() {
float dist = ;
return dist;
}
//colour challenge
void colour_challenge(){
//detect color
if (colour //parameters here) {
red_task();
}
else if (//parameters){
green_task();
}
else if (//parameters) {
yellow_task();
}
else if(//parameters) {
}
//red (left turn)
void red_task(){
left_turn();
}
//green (right turn)
void green_task(){
right_turn()
}
//yellow (U-turn within same grid)
void yellow_task(){
right_turn();
right_turn();
}
//purple (2x left in 2 grid)
void purple_task(){
left_turn();
while(dist_front() > 4) {
//go straight
}
//stop
left_turn();
}
}
//light blue (2x right in 2 grid)
void lightblue_task(){
right_turn();
while(dist_front() > 4) {
//go straight
}
//stop
right_turn();
}
}
//black (make noise)
void black_task(){
}
void setup(){
}
void loop() {
forward();
if(black_strip()){
color_challenge();
}
}