1 | #ifndef BristleBot_h |
---|
2 | #define BristleBot_h |
---|
3 | |
---|
4 | #include <inttypes.h> |
---|
5 | #include <wiring.h> |
---|
6 | |
---|
7 | #define LINKS -1 |
---|
8 | #define RECHTS 1 |
---|
9 | #define BEIDE 0 |
---|
10 | #define WENN if |
---|
11 | #define SONST else |
---|
12 | #define IST == |
---|
13 | #define LOS loop |
---|
14 | #define FERTIG setup |
---|
15 | #define UND && |
---|
16 | #define SCHALTE switch |
---|
17 | #define FALLS case |
---|
18 | #define AN true |
---|
19 | #define AUS false |
---|
20 | |
---|
21 | |
---|
22 | // Klasse des Roboters. Hier werden alle Funktionen und Variablen bestimmt. |
---|
23 | class BristleBot |
---|
24 | { |
---|
25 | |
---|
26 | public: |
---|
27 | |
---|
28 | //=================================================================== |
---|
29 | //Hier werden die Variablen definiert. |
---|
30 | //=================================================================== |
---|
31 | //Wert fuer eingeschalteten Motor Wert. Muss zwischen 0 und 255 liegen. (Darf nicht mehr als 3 Volt sein!!! |
---|
32 | //Bei 5 Volt Stromversorgung darf der Wert nicht hoeher als 180 betragen, sonst brutzeln die Motoren durch) |
---|
33 | int motOn; |
---|
34 | |
---|
35 | //Differenz zwischen beiden Sensoren, um einen hell/dunkel Uebergang zu erkennen. |
---|
36 | int sensibility; |
---|
37 | |
---|
38 | //Variable des Pins fuer linkes Licht vorn. |
---|
39 | int leftLight; |
---|
40 | |
---|
41 | //Variable des Pins fuer rechtes Licht vorn. |
---|
42 | int rightLight; |
---|
43 | |
---|
44 | //Variable des Pins fuer rechtes Licht hinten. |
---|
45 | int backLightRight; |
---|
46 | |
---|
47 | //Variable des Pins fuer linkes Licht hinten. |
---|
48 | int backLightLeft; |
---|
49 | |
---|
50 | //Variable des Pins fuer blaue LED vorn. |
---|
51 | int ledBlue; |
---|
52 | |
---|
53 | //Variable des Pins fuer rechten Sensor. |
---|
54 | int sensorRight; |
---|
55 | |
---|
56 | //Variable des Pins fuer linkes Sensor. |
---|
57 | int sensorLeft; |
---|
58 | |
---|
59 | //Variable des Pins fuer rechten Motor (muss PWN Pin sein!!!). |
---|
60 | int motorRight; |
---|
61 | |
---|
62 | //Variable des Pins fuer linken Motor (muss PWN Pin sein!!!). |
---|
63 | int motorLeft; |
---|
64 | |
---|
65 | //=================================================================== |
---|
66 | //Hier werden die Funktionen definiert. |
---|
67 | //=================================================================== |
---|
68 | |
---|
69 | BristleBot(); |
---|
70 | //Konstruktor des Roboters. Ein neuer Roboter wird erzeugt. |
---|
71 | /* BristleBot() */ |
---|
72 | /* { */ |
---|
73 | /* //Pin fuer linkes Licht vorn. */ |
---|
74 | /* leftLight = 3; */ |
---|
75 | /* //Pin fuer rechtes Licht vorn. */ |
---|
76 | /* rightLight = 7 ; */ |
---|
77 | /* //Pin fuer rechtes Licht hinten. */ |
---|
78 | /* backLightRight = 8 ; */ |
---|
79 | /* //Pin fuer linkes Licht hinten. */ |
---|
80 | /* backLightLeft = 2 ; */ |
---|
81 | /* //Pin fuer blaue LED vorn. */ |
---|
82 | /* ledBlue = 9; */ |
---|
83 | /* //Pin fuer linken Sensor. */ |
---|
84 | /* sensorLeft = 3 ; */ |
---|
85 | /* //Pin fuer rechten Sensor. */ |
---|
86 | /* sensorRight = 2 ; */ |
---|
87 | /* //Pin fuer rechten Motor (muss PWN Pin sein!!!). */ |
---|
88 | /* motorRight = 10; */ |
---|
89 | /* //Pin fuer linken Motor (muss PWN Pin sein!!!). */ |
---|
90 | /* motorLeft = 11; */ |
---|
91 | /* } */ |
---|
92 | |
---|
93 | void stop(); |
---|
94 | //=================================================================== |
---|
95 | //Stopt beide Motoren. |
---|
96 | //=================================================================== |
---|
97 | /* void stop() */ |
---|
98 | /* { */ |
---|
99 | /* //Setze rechten Motor auf 0 Volt */ |
---|
100 | /* analogWrite( motorRight, 0 ); */ |
---|
101 | /* //Setze linken Motor auf 0 Volt */ |
---|
102 | /* analogWrite( motorLeft, 0 ); */ |
---|
103 | /* } */ |
---|
104 | |
---|
105 | void fahreGerade(); |
---|
106 | //=================================================================== |
---|
107 | //Schaltet beie Motoren an. Der Roboter faehrt nach vorn. |
---|
108 | //=================================================================== |
---|
109 | /* void fahreGerade() */ |
---|
110 | /* { */ |
---|
111 | /* //Setze rechten Motor auf maximal Volt (Darf nicht mehr als 3 Volt sein!!!) */ |
---|
112 | /* analogWrite( motorRight, motOn ); */ |
---|
113 | /* //Setze linken Motor auf maximal Volt (Darf nicht mehr als 3 Volt sein!!!) */ |
---|
114 | /* analogWrite( motorLeft, motOn ); */ |
---|
115 | /* } */ |
---|
116 | |
---|
117 | void fahreLinks(); |
---|
118 | //=================================================================== |
---|
119 | //Schaltet rechten Motor an, um eine Linkskurve zu fahren. |
---|
120 | //=================================================================== |
---|
121 | /* void fahreLinks() */ |
---|
122 | /* { */ |
---|
123 | /* //Setze linken Motor auf 0 Volt */ |
---|
124 | /* analogWrite( motorLeft, 0 ); */ |
---|
125 | /* //Setze rechten Motor auf maximal Volt (Darf nicht mehr als 3 Volt sein!!!) */ |
---|
126 | /* analogWrite( motorRight, motOn ); */ |
---|
127 | /* } */ |
---|
128 | |
---|
129 | void fahreRechts(); |
---|
130 | //=================================================================== |
---|
131 | //Schaltet linken Motor an, um eine Rechtskurve zu fahren. |
---|
132 | //=================================================================== |
---|
133 | /* void fahreRechts() */ |
---|
134 | /* { */ |
---|
135 | /* analogWrite( motorRight, 0 ); */ |
---|
136 | /* analogWrite( motorLeft, motOn ); */ |
---|
137 | |
---|
138 | /* } */ |
---|
139 | |
---|
140 | void ruecklicht(bool an); |
---|
141 | //=================================================================== |
---|
142 | //Schalte Ruecklicht an oder aus. Wenn das Ruecklicht angeschaltet werden soll, muss fuer "an" true |
---|
143 | //uebergeben werden. Wenn das Licht ausgeschaltet werden soll, muss fuer "an" false uebergeben werden. |
---|
144 | //=================================================================== |
---|
145 | /* void ruecklicht(bool an) */ |
---|
146 | /* { */ |
---|
147 | /* //Schalte rechtes Ruecklicht an oder aus. */ |
---|
148 | /* digitalWrite(backLightRight, !an); */ |
---|
149 | /* //Schalte linkes Ruecklicht an oder aus. */ |
---|
150 | /* digitalWrite(backLightLeft, !an); */ |
---|
151 | /* } */ |
---|
152 | |
---|
153 | void linkesLicht(bool an); |
---|
154 | //=================================================================== |
---|
155 | //Schalte linkes Licht an oder aus. Wenn das linke Licht angeschaltet werden soll, muss fuer "an" true |
---|
156 | //uebergeben werden. Wenn das Licht ausgeschaltet werden soll, muss fuer "an" false uebergeben werden. |
---|
157 | //=================================================================== |
---|
158 | /* void linkesLicht(bool an) */ |
---|
159 | /* { */ |
---|
160 | /* //Schalte linkes Licht an oder aus. */ |
---|
161 | /* digitalWrite(leftLight, !an); */ |
---|
162 | /* } */ |
---|
163 | |
---|
164 | void rechtesLicht(bool an); |
---|
165 | //=================================================================== |
---|
166 | //Schalte Ruecklicht an oder aus. Wenn das Ruecklicht angeschaltet werden soll, muss fuer "an" true |
---|
167 | //uebergeben werden. Wenn das Licht ausgeschaltet werden soll, muss fuer "an" false uebergeben werden. |
---|
168 | //=================================================================== |
---|
169 | /* void rechtesLicht(bool an) */ |
---|
170 | /* { */ |
---|
171 | /* //Schalte rechtes Licht an oder aus. */ |
---|
172 | /* digitalWrite(rightLight, !an); */ |
---|
173 | /* } */ |
---|
174 | |
---|
175 | int leseSensor(); |
---|
176 | //=================================================================== |
---|
177 | //Lese beide Sensorwerte aus und bestimme, welcher der beiden Sensoren mehr Licht |
---|
178 | //emfaengt bzw. beide Sensoren gleich viel Licht. |
---|
179 | //=================================================================== |
---|
180 | /* int leseSensor() */ |
---|
181 | /* { */ |
---|
182 | /* //Lese rechten Sensorwert ( Wert ist zwischen 0 (kein Licht) und 1024 (ganz hell). */ |
---|
183 | /* int lightRight = analogRead( sensorRight ); */ |
---|
184 | /* //Lese linken Sensorwert ( Wert ist zwischen 0 (kein Licht) und 1024 (ganz hell). */ |
---|
185 | /* int lightLeft = analogRead( sensorLeft ); */ |
---|
186 | |
---|
187 | /* //Entscheide, ob rechter Sensor viel mehr Licht empfaengt als linker Sensor. */ |
---|
188 | /* if( ( lightLeft - lightRight ) < -sensibility ) */ |
---|
189 | /* { */ |
---|
190 | /* return RECHTS; */ |
---|
191 | /* } //Entscheide, ob linker Sensor viel mehr Licht empfaengt als rechter Sensor. */ |
---|
192 | /* else if (( lightLeft - lightRight ) > sensibility ) */ |
---|
193 | /* { */ |
---|
194 | /* return LINKS; */ |
---|
195 | /* } //Ansonsten sind beide Sensorwerte FAST gleich. */ |
---|
196 | /* else */ |
---|
197 | /* { */ |
---|
198 | /* return BEIDE; */ |
---|
199 | /* } */ |
---|
200 | |
---|
201 | /* } */ |
---|
202 | |
---|
203 | void init(int _on, int _sens ); |
---|
204 | //=================================================================== |
---|
205 | //Aktiviere Roboter und fuere einige Tests durch |
---|
206 | //=================================================================== |
---|
207 | /* void init(int _on, int _sens ) */ |
---|
208 | /* { */ |
---|
209 | /* //Setze Wert fuer eingeschalteten Motor Wert. Muss zwischen 0 und 255 liegen. (Darf nicht mehr als 3 Volt sein!!! */ |
---|
210 | /* //Bei 5 Volt Stromversorgung darf der Wert nicht hoeher als 180 betragen, sonst brutzeln die Motoren durch) */ |
---|
211 | /* motOn = _on; */ |
---|
212 | /* //Differenz zwischen beiden Sensoren, um einen hell/dunkel Uebergang zu erkennen. */ |
---|
213 | /* sensibility = _sens; */ |
---|
214 | |
---|
215 | /* //Aktiviere Eingangs/Ausgangs Pins des Microcontrollers */ |
---|
216 | /* pinMode(leftLight, OUTPUT); */ |
---|
217 | /* pinMode(rightLight, OUTPUT); */ |
---|
218 | /* pinMode(backLightRight, OUTPUT); */ |
---|
219 | /* pinMode(backLightLeft, OUTPUT); */ |
---|
220 | /* pinMode(ledBlue, OUTPUT ); */ |
---|
221 | /* //Schalte blaue LED an */ |
---|
222 | /* digitalWrite(ledBlue, LOW); */ |
---|
223 | |
---|
224 | /* //Schalte rechtes Licht an. */ |
---|
225 | /* rechtesLicht(AN); */ |
---|
226 | /* //Schalte linkes Licht aus. */ |
---|
227 | /* linkesLicht(AUS); */ |
---|
228 | /* //Schalte Ruecklicht aus. */ |
---|
229 | /* ruecklicht(AUS); */ |
---|
230 | /* //Warte eine halbe Sekunde. */ |
---|
231 | /* delay(500); */ |
---|
232 | |
---|
233 | /* //Schalte rechtes Licht aus. */ |
---|
234 | /* rechtesLicht(AUS); */ |
---|
235 | /* //Schalte linkes Licht an. */ |
---|
236 | /* linkesLicht(AN); */ |
---|
237 | /* //Schalte Ruecklicht aus. */ |
---|
238 | /* ruecklicht(AUS); */ |
---|
239 | /* //Warte eine halbe Sekunde. */ |
---|
240 | /* delay(500); */ |
---|
241 | |
---|
242 | /* //Schalte rechtes Licht aus. */ |
---|
243 | /* rechtesLicht(AUS); */ |
---|
244 | /* //Schalte linkes Licht aus. */ |
---|
245 | /* linkesLicht(AUS); */ |
---|
246 | /* //Schalte Ruecklicht an. */ |
---|
247 | /* ruecklicht(AN); */ |
---|
248 | /* //Warte eine halbe Sekunde. */ |
---|
249 | /* delay(500); */ |
---|
250 | |
---|
251 | /* //Schalte rechtes Licht aus. */ |
---|
252 | /* rechtesLicht(AUS); */ |
---|
253 | /* //Schalte linkes Licht aus. */ |
---|
254 | /* linkesLicht(AUS); */ |
---|
255 | /* //Schalte Ruecklicht aus. */ |
---|
256 | /* ruecklicht(AUS); */ |
---|
257 | /* //Warte eine halbe Sekunde. */ |
---|
258 | /* delay(500); */ |
---|
259 | |
---|
260 | /* //Fahre Rechtskurve. */ |
---|
261 | /* fahreRechts(); */ |
---|
262 | /* //Fahre drei Sekunden lang. */ |
---|
263 | /* delay(3000); */ |
---|
264 | /* //Fahre Linksskurve. */ |
---|
265 | /* fahreLinks(); */ |
---|
266 | /* //Warte drei Sekunden. */ |
---|
267 | /* delay(3000); */ |
---|
268 | /* //Fahre Linksskurve. */ |
---|
269 | /* fahreLinks(); */ |
---|
270 | /* //Fahre drei Sekunden lang. */ |
---|
271 | /* delay(3000); */ |
---|
272 | /* } */ |
---|
273 | |
---|
274 | }; |
---|
275 | |
---|
276 | #endif |
---|
277 | |
---|