-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloWorldChallenge
More file actions
197 lines (169 loc) · 6.91 KB
/
HelloWorldChallenge
File metadata and controls
197 lines (169 loc) · 6.91 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// Sends a message to debug listeners
misty.Debug("The HelloWorld skill challenge is starting!")
// Global Variables for _breathingLED RGB values
_colorloop = 0;
_red = 140 / 10.0;
_green = 0 / 10.0;
_blue = 0 / 220.0;
// Changes RGB values depending on loop value for _breathingLED
function ledColor() {
switch(_colorloop) {
case 1: // Red
_red = 220 / 10.0;
_green = 0 / 10.0;
_blue = 0 / 10.0;
break;
case 2: // Yellow
_red = 220 / 10.0;
_green = 220 / 10.0;
_blue = 0 / 10.0;
break;
case 3: // Green
_red = 0 / 10.0;
_green = 220 / 10.0;
_blue = 0 / 10.0;
break;
case 4: // Cyan
_red = 0 / 10.0;
_green = 220 / 10.0;
_blue = 220 / 10.0;
break;
case 5: // Blue
_red = 0 / 10.0;
_green = 0 / 10.0;
_blue = 220 / 10.0;
break;
default: // Purple
_red = 140 / 10.0;
_green = 0 / 10.0;
_blue = 220 / 10.0;
}
}
// Plays an audio file at max volume.
misty.PlayAudio("s_Amazement.wav", 100);
// Pauses for 3000 milliseconds before executing the next command.
misty.Pause(3000);
// Returns a random integer between min and max
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
misty.RegisterTimerEvent("look_around", getRandomInt(5, 10) * 1000, false);
// The look_around timer event invokes this callback function.
function _look_around(repeat = true) {
// Moves Misty's head to a random position. Adjust the min/max
// values passed into getRandomInt() to change Misty's range of
// motion when she calls this method.
misty.MoveHeadDegrees(
getRandomInt(-40, -10), // Random pitch position between -40 and 20
getRandomInt(-20, 20), // Random roll position between -30 and 30
getRandomInt(-25, 25), // Random yaw position between -40 and 40
30); // Head movement velocity. Can increase up to 100.
// If repeat is set to true, re-registers for the look_around
// timer event, and Misty moves her head until the skill ends.
if (repeat) misty.RegisterTimerEvent(
"look_around",
getRandomInt(5, 10) * 1000,
false);
}
// Registers for a timer event called breathingLED, and invokes the
// _breathingLED() callback after 1 millisecond.
misty.RegisterTimerEvent("breathingLED", 1, false);
// The breathingLED timer event invokes this callback function.
function _breathingLED() {
// calls function to update global color variable
ledColor();
// Incrementally DECREASES the intensity of each color in the LED
for (var i = 10; i >= 0; i = i - 1) {
misty.ChangeLED(
Math.floor(i * _red), // red intensity ***CHANGED TO GLOBAL VAR***
Math.floor(i * _green), // green intensity ***CHANGED TO GLOBAL VAR***
Math.floor(i * _blue)); // blue intensity ***CHANGED TO GLOBAL VAR***
// Pause before next iteration. Increase value for slower
// breathing; decrease for faster breathing.
misty.Pause(150);
}
// Goes to next color
_colorloop = _colorloop + 1;
// Resets list back to beginning if cycle complete
if(_colorloop > 5) {
_colorloop = 0;
}
// calls function to update global color variable
ledColor();
// Incrementally INCREASES the intensity of each color in the LED
for (var i = 0; i <= 10; i = i + 1) {
misty.ChangeLED(
Math.floor(i * _red), // red intensity ***CHANGED TO GLOBAL VAR***
Math.floor(i * _green), // green intensity ***CHANGED TO GLOBAL VAR***
Math.floor(i * _blue)); // blue intensity ***CHANGED TO GLOBAL VAR***
// Pause before next iteration. Increase value for slower
// breathing; decrease for faster breathing.
misty.Pause(150);
}
// Re-registers for the breathingLED timer event, so Misty's LED
// continues breathing until the skill ends.
misty.RegisterTimerEvent("breathingLED", 1, false);
}
// Registers for a timer event called breathingLED, and invokes the
// _breathingLED() callback after 1 millisecond.
misty.RegisterTimerEvent("breathingLED", 1, false);
// Waves Misty's right arm!
function waveRightArm() {
misty.MoveArmDegrees("right", -80, 30); // Right arm up to wave
misty.Pause(3000); // Pause with arm up for 3 seconds
misty.MoveArmDegrees("both", 80, 30); // Both arms down
}
waveRightArm();
// Invoke this function to start Misty recognizing faces.
function _registerFaceRec() {
// Cancels any face recognition that's currently underway
misty.StopFaceRecognition();
// Starts face recognition
misty.StartFaceRecognition();
// If a FaceRecognition event includes a "PersonName" property,
// then Misty invokes the _FaceRec callback function.
misty.AddPropertyTest("FaceRec", "PersonName", "exists", "", "string");
// Registers for FaceRecognition events. Sets eventName to FaceRec,
// debounceMs to 1000, and keepAlive to false.
misty.RegisterEvent("FaceRec", "FaceRecognition", 1000, false);
}
// FaceRec events invoke this callback function.
function _FaceRec(data) {
// Stores the value of the detected face
var faceDetected = data.PropertyTestResults[0].PropertyValue;
// Logs a debug message with the label of the detected face
misty.Debug("Misty sees " + faceDetected);
// Use the Command Center to train Misty to recognize your face.
// Then, replace <Your-Name> below with your own name! If Misty
// sees and recognizes you, she waves and looks happy.
if (faceDetected == "Jeff") {
misty.DisplayImage("e_Joy.jpg");
misty.PlayAudio("SkillsDeveloper.mp3");
waveRightArm();
}
if (faceDetected == "Tutu") {
misty.DisplayImage("e_Joy.jpg");
misty.PlayAudio("LookingGood.mp3");
waveRightArm();
}
// If Misty sees someone she doesn't know, she raises her eyebrow
// and plays a different sound.
else if (faceDetected == "unknown person") {
misty.DisplayImage("e_Contempt.jpg");
misty.PlayAudio("RobotHater.mp3");
misty.Pause(4000); // Pause with arm up for 4 seconds
misty.PlayAudio("WeaponCharge.wav");
misty.MoveArmDegrees("both", 0, 40); // Both arms out
misty.Pause(4000); // Pause with arm up for 4 seconds
misty.MoveArmDegrees("both", 80, 30); // Both arms down
};
misty.Pause(3000); // Pause for 3 seconds
// Rest to default eyes
misty.DisplayImage("e_DefaultContent.jpg");
// Register for a timer event to invoke the _registerFaceRec
// callback function loop through the _registerFaceRec() again
// after 7000 milliseconds pass.
misty.RegisterTimerEvent("registerFaceRec", 7000, false);
}
// Starts Misty recognizing faces!
_registerFaceRec();