Skip to content

Commit 5d06193

Browse files
committed
Added more user-callible eye functions.
Added additional eye functions (close, wide), to replace boop and blink functions on the Wiichuck button functions for better eye puppetry. Other minor style and debugging changes.
1 parent 1a7b469 commit 5d06193

File tree

4 files changed

+44
-28
lines changed

4 files changed

+44
-28
lines changed

M4_Eyes/M4_Eyes.ino

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ int iPupilFactor = 42;
5959
uint32_t boopSum = 0,
6060
boopSumFiltered = 0;
6161
bool booped = false;
62+
bool eyelidsClosed = false;
6263
bool eyelidsWide = false;
6364
int fixate = 7;
6465
uint8_t lightSensorFailCount = 0;
@@ -136,24 +137,36 @@ uint32_t availableRAM(void) {
136137

137138
// USER CALLABLE FUNCTIONS
138139

140+
// Start a blink.
141+
void eyesBlink() {
142+
Serial.println("eyesBlink()");
143+
timeToNextBlink = 0;
144+
}
145+
139146
// Force the booped flag to be set true.
140147
void eyesBoop() {
141148
Serial.println("eyesBoop()");
142149
boopSum = 99999;
143150
}
144151

152+
// Close eyelids.
153+
void eyesClose() {
154+
Serial.println("eyesClose()");
155+
eyelidsClosed = true;
156+
}
157+
158+
// Return the eyes to normal random movement.
159+
void eyesNormal() {
160+
// Serial.println("eyesNormal()");
161+
moveEyesRandomly = true;
162+
}
163+
145164
// Open eyelids wide.
146165
void eyesWide() {
147166
Serial.println("eyesWide()");
148167
eyelidsWide = true;
149168
}
150169

151-
// Start a blink.
152-
void eyesBlink() {
153-
Serial.println("eyesBlink()");
154-
timeToNextBlink = 0;
155-
}
156-
157170
// Force the eyes to a position on the screen.
158171
void eyesToCorner(float x, float y, bool immediate) {
159172
moveEyesRandomly = false;
@@ -163,12 +176,6 @@ void eyesToCorner(float x, float y, bool immediate) {
163176
eyeMoveDuration = 0;
164177
}
165178

166-
// Return the eyes to normal random movement.
167-
void eyesNormal() {
168-
// Serial.println("eyesNormal()");
169-
moveEyesRandomly = true;
170-
}
171-
172179

173180
// SETUP FUNCTION - CALLED ONCE AT PROGRAM START ---------------------------
174181

@@ -594,24 +601,31 @@ void loop() {
594601
iy = (int)map2screen(mapRadius - eye[eyeNum].eyeY) + (DISPLAY_SIZE/2); // on screen
595602
iy += irisRadius * trackFactor;
596603
if(eyeNum & 1) ix = DISPLAY_SIZE - 1 - ix; // Flip for right eye
597-
if(iy > upperOpen[ix]) {
604+
if(eyelidsWide) {
598605
uq = 1.0;
599-
} else if(iy < upperClosed[ix]) {
600-
uq = 0.0;
601-
} else {
602-
uq = (float)(iy - upperClosed[ix]) / (float)(upperOpen[ix] - upperClosed[ix]);
603-
}
604-
if(booped || eyelidsWide) {
606+
lq = 1.0;
607+
} else if(booped) {
605608
uq = 0.9;
606609
lq = 0.7;
607610
} else {
611+
if(iy > upperOpen[ix]) {
612+
uq = 1.0;
613+
} else if(iy < upperClosed[ix]) {
614+
uq = 0.0;
615+
} else {
616+
uq = (float)(iy - upperClosed[ix]) / (float)(upperOpen[ix] - upperClosed[ix]);
617+
}
608618
lq = 1.0 - uq;
609619
}
610620
} else {
611621
// If no tracking, eye is FULLY OPEN when not blinking
612622
uq = 1.0;
613623
lq = 1.0;
614624
}
625+
if(eyelidsClosed) {
626+
uq = 0.0;
627+
lq = 0.0;
628+
}
615629
// Dampen eyelid movements slightly
616630
// SAVE upper & lower lid factors per eye,
617631
// they need to stay consistent across frame
@@ -661,8 +675,9 @@ void loop() {
661675
boopSum = 0;
662676
}
663677

664-
// Once per frame (of eye #1), reset eyelidsWide...
665-
if((eyeNum == 1) && (eyelidsWide)) {
678+
// Once per frame (of eye #1), reset eyelid states...
679+
if(eyeNum == 1) {
680+
eyelidsClosed = false;
666681
eyelidsWide = false;
667682
}
668683

M4_Eyes/globals.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ extern void user_setup(StaticJsonDocument<2048> &doc);
243243
extern void user_loop(void);
244244

245245
// User callable functions in M4_Eyes.ino
246+
extern void eyesBlink();
246247
extern void eyesBoop();
248+
extern void eyesClose();
249+
extern void eyesNormal();
247250
extern void eyesWide();
248-
extern void eyesBlink();
249251
extern void eyesToCorner(float x, float y, bool immediate);
250-
extern void eyesNormal();

M4_Eyes/user.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if 1 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
1+
#if 0 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
22

33
// This file provides a crude way to "drop in" user code to the eyes,
44
// allowing concurrent operations without having to maintain a bunch of

M4_Eyes/user_wiichuck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if 0 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
1+
#if 1 // Change to 0 to disable this code (must enable ONE user*.cpp only!)
22

33
// This user loop is designed to be used with a WiiChuck for command inputs and
44
// connects to a NeoPixel strip for additional output. It was used with a unicorn
@@ -183,12 +183,12 @@ void user_loop(void) {
183183
int cornerX = (joyX - low) / divFactor;
184184
int cornerY = (joyY - low) / divFactor;
185185
int chaseColor = 0;
186-
// Serial.println("cornerXY=" + String(cornerX) + "," + String(cornerY));
186+
// Serial.println("cornerXY=" + String(cornerX) + "," + String(cornerY));
187187
if(cornerX == 1 && cornerY == 1) { // return to normal when the joystick is in the middle
188188
eyesNormal();
189189
neoPixelState = LUMINESCENT;
190190
} else {
191-
// Serial.println("eyesToCorner(" + String(x) + "," + String(-y) + ")");
191+
// Serial.println("eyesToCorner(" + String(x) + "," + String(-y) + ")");
192192
eyesToCorner(x, -y, true);
193193
if(cornerX < 1) {
194194
chaseColor = green;
@@ -220,7 +220,7 @@ void user_loop(void) {
220220
neoPixelState = SPARKLE;
221221
} else if(buttonZ) {
222222
Serial.println("buttonZ");
223-
eyesBlink();
223+
eyesClose();
224224
}
225225
}
226226

0 commit comments

Comments
 (0)