Skip to content

Commit bce5734

Browse files
committed
Add code from the new years dance off.
1 parent 51b9208 commit bce5734

File tree

4 files changed

+184
-23
lines changed

4 files changed

+184
-23
lines changed

Diff for: Danceoff.cpp

+136-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "Danceoff.h"
22

3-
Danceoff::Danceoff(Car* car) {
3+
Danceoff::Danceoff(Car *car)
4+
{
45
_car = car;
56
}
67

@@ -13,11 +14,13 @@ Danceoff::Danceoff(Car* car) {
1314
// car->stop();
1415
// delay(milliseconds)
1516

16-
void Danceoff::dance0() {
17-
17+
void Danceoff::dance0()
18+
{
19+
1820
_car->setSpeed(100);
1921

20-
for (int i = 0; i < 10; i++) {
22+
for (int i = 0; i < 10; i++)
23+
{
2124
_car->moveForward();
2225
delay(500);
2326
_car->turnLeft();
@@ -27,13 +30,140 @@ void Danceoff::dance0() {
2730
_car->turnLeft();
2831
delay(500);
2932
}
33+
3034
_car->stop();
3135
}
3236

37+
void Danceoff::dance1()
38+
{
39+
_car->setSpeed(100);
40+
41+
for (int i = 0; i < 20; i++)
42+
{
43+
_car->turnLeft();
44+
delay(250);
45+
_car->moveForward();
46+
delay(250);
47+
}
48+
49+
_car->moveBackward();
50+
delay(2000);
51+
52+
_car->moveForward();
53+
delay(2000);
54+
55+
_car->turnRight();
56+
delay(2000);
57+
58+
_car->turnLeft();
59+
delay(2000);
3360

34-
void Danceoff::dance1() {
61+
_car->moveBackward();
62+
delay(2000);
63+
64+
_car->stop();
65+
}
3566

67+
void Danceoff::dance2()
68+
{
3669
_car->setSpeed(100);
37-
3870

71+
_car->turnLeft();
72+
delay(5000);
73+
74+
_car->moveForward();
75+
delay(500);
76+
77+
_car->turnRight();
78+
delay(5000);
79+
80+
_car->moveForward();
81+
delay(500);
82+
83+
_car->moveBackward();
84+
delay(500);
85+
86+
_car->turnLeft();
87+
delay(500);
88+
89+
_car->moveBackward();
90+
delay(2500);
91+
92+
_car->turnRight();
93+
delay(500);
94+
95+
_car->moveForward();
96+
delay(500);
97+
98+
_car->moveBackward();
99+
delay(500);
100+
101+
_car->stop();
102+
}
103+
104+
void Danceoff::dance3()
105+
{
106+
107+
_car->setSpeed(100);
108+
109+
for (int i = 0; i < 10; i++)
110+
{
111+
_car->moveBackward();
112+
delay(250);
113+
114+
_car->moveForward();
115+
delay(250);
116+
}
117+
118+
for (int i = 0; i < 3; i++)
119+
{
120+
_car->turnLeft();
121+
delay(1000);
122+
123+
_car->turnRight();
124+
delay(1000);
125+
}
126+
127+
for (int i = 0; i < 10; i++)
128+
{
129+
_car->moveForward();
130+
delay(250);
131+
132+
_car->turnLeft();
133+
delay(250);
134+
135+
_car->moveBackward();
136+
delay(250);
137+
138+
_car->turnRight();
139+
delay(250);
140+
}
141+
142+
_car->stop();
143+
}
144+
145+
int Danceoff::length()
146+
{
147+
return 4;
148+
}
149+
150+
void Danceoff::dance(int number)
151+
{
152+
switch (number)
153+
{
154+
case 0:
155+
dance0();
156+
break;
157+
case 1:
158+
dance1();
159+
break;
160+
case 2:
161+
dance2();
162+
break;
163+
case 3:
164+
dance3();
165+
break;
166+
default:
167+
break;
168+
}
39169
}

Diff for: Danceoff.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
#include <Arduino.h>
55
#include "Car.h"
66

7+
// TODO: split each dance into a seperate class
8+
79
class Danceoff
810
{
9-
Car* _car;
11+
Car *_car;
1012

1113
public:
1214
Danceoff(Car *car);
13-
15+
1416
void dance0();
1517
void dance1();
1618
void dance2();
1719
void dance3();
20+
21+
int length();
22+
void dance(int number);
1823
};
1924

2025
#endif

Diff for: README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
## License
44

5-
Read the LICENSE file included in the repository.
5+
Read the LICENSE file included in the repository.
66

77
## Overview
88

99
This is a personal arduino project based on the LAFVIIN Multi-Functional Smart Car Kit.
1010

1111
### Danceoff
1212

13-
This is a class I wrote with my kids to program the robot to do certian dances. After we were done, we had a danceoff where we had someone vote for their favorite dance.
13+
This is a class I wrote with my kids and wife to program the robot to do a dance they came up with. After we were done, we had a danceoff where we had a 3rd party vote for their favorite dance.
14+
15+
dance3 was the winner.
1416

1517
## Tooling
1618

17-
Use the arduino IDE to load, or VS code after setting it up for c++/arduino development.
19+
Use the Arduino IDE to load, or Arduino extension for VS Code after setting it up for C++/Arduino development.

Diff for: arduino-bot.ino

+36-12
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,70 @@ void setup()
1717

1818
tinyDancer = new Danceoff(car);
1919

20-
// Setup Serial
20+
// I have a bluetooth card which is wired to send data over the serial port.
2121
Serial.begin(9600);
2222
}
2323

24+
void allDances()
25+
{
26+
for (int i = 0; i < tinyDancer->length(); i++)
27+
{
28+
tinyDancer->dance(i);
29+
}
30+
}
31+
2432
void serialControl()
2533
{
2634
if (Serial.available())
2735
{
28-
unsigned char direction = Serial.read();
29-
36+
unsigned char command = Serial.read();
3037
car->setSpeed(100);
31-
switch (direction)
38+
switch (command)
3239
{
3340
case 'F':
3441
car->moveForward();
42+
delay(1000);
43+
car->stop();
44+
3545
break;
3646
case 'B':
3747
car->moveBackward();
48+
delay(1000);
49+
car->stop();
50+
3851
break;
3952
case 'L':
4053
car->turnLeft();
54+
4155
break;
4256
case 'R':
4357
car->turnRight();
4458
break;
4559
case 'S':
4660
car->stop();
4761
break;
48-
case 'D':
49-
//dance();
62+
63+
// TODO: store this in some sort of dictionary, and get rid of the switch
64+
case '0':
65+
tinyDancer->dance0();
66+
break;
67+
case '1':
68+
tinyDancer->dance1();
69+
break;
70+
case '2':
71+
tinyDancer->dance2();
72+
break;
73+
case '3':
74+
tinyDancer->dance3();
75+
break;
76+
case '4':
77+
allDances();
5078
break;
5179
}
5280
}
5381
}
5482

5583
void loop()
5684
{
57-
tinyDancer->dance0();
58-
59-
while (true) {
60-
delay(500);
61-
}
62-
}
85+
serialControl();
86+
}

0 commit comments

Comments
 (0)