Skip to content

Commit 1a7b469

Browse files
committed
Made eyesWide() user function distinct from eyesBoop(), a new function.
1 parent a66999f commit 1a7b469

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

M4_Eyes/M4_Eyes.ino

Lines changed: 29 additions & 17 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 eyelidsWide = false;
6263
int fixate = 7;
6364
uint8_t lightSensorFailCount = 0;
6465

@@ -136,14 +137,20 @@ uint32_t availableRAM(void) {
136137
// USER CALLABLE FUNCTIONS
137138

138139
// Force the booped flag to be set true.
139-
void eyesWide() {
140-
// Serial.println("eyesWide()");
140+
void eyesBoop() {
141+
Serial.println("eyesBoop()");
141142
boopSum = 99999;
142143
}
143144

145+
// Open eyelids wide.
146+
void eyesWide() {
147+
Serial.println("eyesWide()");
148+
eyelidsWide = true;
149+
}
150+
144151
// Start a blink.
145152
void eyesBlink() {
146-
// Serial.println("eyesBlink()");
153+
Serial.println("eyesBlink()");
147154
timeToNextBlink = 0;
148155
}
149156

@@ -158,7 +165,7 @@ void eyesToCorner(float x, float y, bool immediate) {
158165

159166
// Return the eyes to normal random movement.
160167
void eyesNormal() {
161-
// Serial.println("eyesNormal()");
168+
// Serial.println("eyesNormal()");
162169
moveEyesRandomly = true;
163170
}
164171

@@ -508,24 +515,24 @@ void loop() {
508515
// Eye movement
509516
int32_t dt = t - eyeMoveStartTime; // uS elapsed since last eye event
510517
if(eyeInMotion) { // Currently moving?
511-
if(dt >= eyeMoveDuration) { // Time up? Destination reached.
512-
eyeInMotion = false; // Stop moving
518+
if(dt >= eyeMoveDuration) { // Time up? Destination reached.
519+
eyeInMotion = false; // Stop moving
513520
if(moveEyesRandomly) {
514-
eyeMoveDuration = random(10000, 3000000); // 0.01-3 sec stop
515-
eyeMoveStartTime = t; // Save initial time of stop
521+
eyeMoveDuration = random(10000, 3000000); // 0.01-3 sec stop
522+
eyeMoveStartTime = t; // Save initial time of stop
516523
}
517524
eyeX = eyeOldX = eyeNewX; // Save position
518525
eyeY = eyeOldY = eyeNewY;
519526
} else { // Move time's not yet fully elapsed -- interpolate position
520527
float e = (float)dt / float(eyeMoveDuration); // 0.0 to 1.0 during move
521528
e = 3 * e * e - 2 * e * e * e; // Easing function: 3*e^2-2*e^3 0.0 to 1.0
522-
eyeX = eyeOldX + (eyeNewX - eyeOldX) * e; // Interp X
523-
eyeY = eyeOldY + (eyeNewY - eyeOldY) * e; // and Y
529+
eyeX = eyeOldX + (eyeNewX - eyeOldX) * e; // Interp X
530+
eyeY = eyeOldY + (eyeNewY - eyeOldY) * e; // and Y
524531
}
525-
} else { // Eye stopped
532+
} else { // Eye stopped
526533
eyeX = eyeOldX;
527534
eyeY = eyeOldY;
528-
if(dt > eyeMoveDuration) { // Time up? Begin new move.
535+
if(dt > eyeMoveDuration) { // Time up? Begin new move.
529536
// r is the radius in X and Y that the eye can go, from (0,0) in the center.
530537
float r = (float)mapDiameter - (float)DISPLAY_SIZE * M_PI_2; // radius of motion
531538
r *= 0.6; // calibration constant
@@ -543,9 +550,9 @@ void loop() {
543550
eyeNewY += mapRadius;
544551

545552
// Set the duration for this move, and start it going.
546-
eyeMoveDuration = random(83000, 166000); // ~1/12 - ~1/6 sec
547-
eyeMoveStartTime = t; // Save initial time of move
548-
eyeInMotion = true; // Start move on next frame
553+
eyeMoveDuration = random(83000, 166000); // ~1/12 - ~1/6 sec
554+
eyeMoveStartTime = t; // Save initial time of move
555+
eyeInMotion = true; // Start move on next frame
549556
}
550557
}
551558

@@ -594,7 +601,7 @@ void loop() {
594601
} else {
595602
uq = (float)(iy - upperClosed[ix]) / (float)(upperOpen[ix] - upperClosed[ix]);
596603
}
597-
if(booped) {
604+
if(booped || eyelidsWide) {
598605
uq = 0.9;
599606
lq = 0.7;
600607
} else {
@@ -642,7 +649,7 @@ void loop() {
642649
// Once per frame (of eye #0), reset boopSum...
643650
if((eyeNum == 0) && (boopPin >= 0)) {
644651
boopSumFiltered = ((boopSumFiltered * 3) + boopSum) / 4;
645-
// Serial.printf("boopSum: %d, boopSumFiltered: %d, boopThreshold: %d, booped: %s\n", boopSum, boopSumFiltered, boopThreshold, (booped ? "true" : "false"));
652+
// Serial.printf("boopSum: %d, boopSumFiltered: %d, boopThreshold: %d, booped: %s\n", boopSum, boopSumFiltered, boopThreshold, (booped ? "true" : "false"));
646653
if(boopSumFiltered > boopThreshold) {
647654
if(!booped) {
648655
Serial.println("BOOP!");
@@ -654,6 +661,11 @@ void loop() {
654661
boopSum = 0;
655662
}
656663

664+
// Once per frame (of eye #1), reset eyelidsWide...
665+
if((eyeNum == 1) && (eyelidsWide)) {
666+
eyelidsWide = false;
667+
}
668+
657669
float mins = (float)millis() / 60000.0;
658670
if(eye[eyeNum].iris.iSpin) {
659671
// Spin works in fixed amount per frame (eyes may lose sync, but "wagon wheel" tricks work)

M4_Eyes/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ 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 eyesBoop();
246247
extern void eyesWide();
247248
extern void eyesBlink();
248249
extern void eyesToCorner(float x, float y, bool immediate);

M4_Eyes/user_wiichuck.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ void user_setup(StaticJsonDocument<2048> &doc) {
8787

8888
const char *neopin = doc["wiichuck"]["neopixel"]["pin"];
8989
Serial.println("neopin=" + String(neopin ? neopin : "(null)"));
90-
int32_t neomax = getDocInt(doc, "wiichuck","neopixel","max",-1);
90+
int32_t neomax = getDocInt(doc, "wiichuck", "neopixel", "max", -1);
9191
Serial.println("neopin=" + String(neomax));
9292

9393
if(neopin && neomax > -1) {
@@ -106,8 +106,7 @@ void user_setup(StaticJsonDocument<2048> &doc) {
106106
}
107107
}
108108

109-
static void neoChase(int addend, int div, int color)
110-
{
109+
static void neoChase(int addend, int div, int color) {
111110
curChasePixel += addend;
112111
curChasePixel %= div;
113112

@@ -118,8 +117,7 @@ static void neoChase(int addend, int div, int color)
118117
strip.show();
119118
}
120119

121-
static void neoUpDown(int color, int dir)
122-
{
120+
static void neoUpDown(int color, int dir) {
123121
int np = strip.numPixels();
124122
curChasePixel += np + dir;
125123
curChasePixel %= np;
@@ -130,8 +128,7 @@ static void neoUpDown(int color, int dir)
130128
strip.show();
131129
}
132130

133-
static void neoShine()
134-
{
131+
static void neoShine() {
135132
// code from user_neopixel.cpp
136133
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
137134
// Offset pixel hue by an amount to make one full revolution of the
@@ -149,16 +146,14 @@ static void neoShine()
149146
firstPixelHue += 256;
150147
}
151148

152-
static void neoSparkle()
153-
{
149+
static void neoSparkle() {
154150
strip.clear();
155151
int i = random(0, strip.numPixels());
156152
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
157153
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
158154
strip.show(); // Update strip with new contents
159155
}
160156

161-
162157
// the normal map() function doesn't seem to work properly for floats
163158
static float map2(long x, long in_min, long in_max, float out_min, float out_max) {
164159
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;

0 commit comments

Comments
 (0)