@@ -68,6 +68,9 @@ float iris_prev[IRIS_LEVELS] = { 0 };
6868float iris_next[IRIS_LEVELS] = { 0 };
6969uint16_t iris_frame = 0 ;
7070
71+ // For heat sensing
72+ HeatSensor heatSensor;
73+
7174// Callback invoked after each SPI DMA transfer - sets a flag indicating
7275// the next line of graphics can be issued as soon as its ready.
7376static void dma_callback (Adafruit_ZeroDMA *dma) {
@@ -184,6 +187,7 @@ void setup() {
184187 eye[0 ].display = arcada.display ;
185188 #endif
186189
190+ #ifdef DO_SPLASH_SCREEN
187191 yield ();
188192 if (arcada.drawBMP (" /splash.bmp" , 0 , 0 , (eye[0 ].display )) == IMAGE_SUCCESS) {
189193 Serial.println (" Splashing" );
@@ -203,6 +207,7 @@ void setup() {
203207 delay (20 );
204208 }
205209 }
210+ #endif
206211
207212 // Initialize DMAs
208213 yield ();
@@ -417,6 +422,7 @@ void setup() {
417422 }
418423
419424 user_setup ();
425+ heatSensor.setup ();
420426
421427 lastLightReadTime = micros () + 2000000 ; // Delay initial light reading
422428}
@@ -475,8 +481,8 @@ void loop() {
475481 if (eyeInMotion) { // Currently moving?
476482 if (dt >= eyeMoveDuration) { // Time up? Destination reached.
477483 eyeInMotion = false ; // Stop moving
478- eyeMoveDuration = random (10000 , 3000000 ); // 0.01-3 sec stop
479- eyeMoveStartTime = t; // Save initial time of stop
484+ // eyeMoveDuration = random(10000, 3000000); // 0.01-3 sec stop
485+ // eyeMoveStartTime = t; // Save initial time of stop
480486 eyeX = eyeOldX = eyeNewX; // Save position
481487 eyeY = eyeOldY = eyeNewY;
482488 } else { // Move time's not yet fully elapsed -- interpolate position
@@ -489,13 +495,22 @@ void loop() {
489495 eyeX = eyeOldX;
490496 eyeY = eyeOldY;
491497 if (dt > eyeMoveDuration) { // Time up? Begin new move.
498+ // Estimate the focus position.
499+ heatSensor.find_focus ();
500+
501+ // r is the radius in X and Y that the eye can go, from (0,0) in the center.
492502 float r = (float )mapDiameter - (float )DISPLAY_SIZE * M_PI_2; // radius of motion
493- r *= 0.6 ;
494- eyeNewX = random (-r, r);
495- float h = sqrt (r * r - x * x);
496- eyeNewY = random (-h, h);
503+ r *= 0.6 ; // calibration constant
504+
505+ // Set values for the new X and Y.
506+ eyeNewX = heatSensor.x * r;
507+ eyeNewY = -heatSensor.y * r;
508+
509+ // Adjust for the map.
497510 eyeNewX += mapRadius;
498511 eyeNewY += mapRadius;
512+
513+ // Set the duration for this move, and start it going.
499514 eyeMoveDuration = random (83000 , 166000 ); // ~1/12 - ~1/6 sec
500515 eyeMoveStartTime = t; // Save initial time of move
501516 eyeInMotion = true ; // Start move on next frame
@@ -870,8 +885,7 @@ void loop() {
870885 lightSensorPin = -1 ; // Stop trying to use the light sensor
871886 } else {
872887 lastLightReadTime = t - LIGHT_INTERVAL + 30000 ; // Try again in 30 ms
873- }
874- }
888+ } }
875889 }
876890 irisValue = (irisValue * 0.97 ) + (lastLightValue * 0.03 ); // Filter response for smooth reaction
877891 } else {
0 commit comments