Skip to content

Commit 243aabc

Browse files
authored
Merge pull request #878 from adafruit/TheKitty-patch-105
Files for the guide Monster M4sk Is Watching You
2 parents dd95657 + 6b23535 commit 243aabc

71 files changed

Lines changed: 2648 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Very infrequently the jobStatus member in Adafruit_ZeroDMA gets out of
2+
// sync and the screen DMA updates lock up. This is a hacky workaround.
3+
// jobStatus is a protected member of Adafruit_ZeroDMA, we can't reset it
4+
// directly in the sketch, but a subclass can. So we have this minimal
5+
// subclass with a DMA-channel-toggle-off-on-and-jobStatus-reset function.
6+
7+
class DMAbuddy : public Adafruit_ZeroDMA {
8+
public:
9+
// Call this function when a DMA stall is detected:
10+
void fix(void) {
11+
// We literally just switch the channel off and on again to fix it...
12+
DMAC->Channel[channel].CHCTRLA.bit.ENABLE = 0; // Disable channel
13+
DMAC->Channel[channel].CHCTRLA.bit.ENABLE = 1; // Enable channel
14+
jobStatus = DMA_STATUS_OK; // Back in business!
15+
}
16+
};
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/* Read the IR sensor and try to figure out where the heat is located.
2+
*/
3+
4+
#include "HeatSensor.h"
5+
6+
#include <Wire.h>
7+
#include <Adafruit_AMG88xx.h>
8+
9+
Adafruit_AMG88xx amg;
10+
11+
float pixels[AMG88xx_PIXEL_ARRAY_SIZE];
12+
13+
void HeatSensor::setup()
14+
{
15+
x = 0;
16+
y = 0;
17+
magnitude = 0;
18+
19+
bool status;
20+
21+
// default settings
22+
status = amg.begin();
23+
if (!status) {
24+
Serial.println("Could not find a valid AMG88xx sensor, check wiring!");
25+
while (1);
26+
}
27+
28+
yield();
29+
delay(100); // let sensor boot up
30+
}
31+
32+
// Find the approximate X and Y values of the peak temperature in the pixel array,
33+
// along with the magnitude of the brightest spot.
34+
void HeatSensor::find_focus()
35+
{
36+
amg.readPixels(pixels);
37+
yield();
38+
39+
x = 0, y = 0, magnitude = 0;
40+
float minVal = 100, maxVal = 0;
41+
int i = 0;
42+
for (float yPos = 3.5; yPos > -4; yPos -= 1.0) {
43+
for (float xPos = 3.5; xPos > -4; xPos -= 1.0) {
44+
float p = pixels[i];
45+
x += xPos * p;
46+
y += yPos * p;
47+
minVal = min(minVal, p);
48+
maxVal = max(maxVal, p);
49+
i++;
50+
}
51+
}
52+
x = - x / AMG88xx_PIXEL_ARRAY_SIZE / 5.0;
53+
y = y / AMG88xx_PIXEL_ARRAY_SIZE / 5.0;
54+
x = max(-1.0, min(1.0, x));
55+
y = max(-1.0, min(1.0, y));
56+
magnitude = max(0, min(50, maxVal - 20));
57+
58+
// Report.
59+
#define SERIAL_OUT 3
60+
#if SERIAL_OUT == 1
61+
// Print raw values
62+
Serial.print("[");
63+
for(int i=1; i<=AMG88xx_PIXEL_ARRAY_SIZE; i++){
64+
Serial.print(pixels[i-1]);
65+
Serial.print(", ");
66+
if( i%8 == 0 ) Serial.println();
67+
}
68+
Serial.println("]");
69+
Serial.println();
70+
#endif
71+
#if SERIAL_OUT == 2
72+
// Print character-graphic array
73+
const char charPixels[] = " .-*o0#";
74+
Serial.println("========");
75+
for (int i = 1; i <= AMG88xx_PIXEL_ARRAY_SIZE; i++) {
76+
int val = min(5, round(max(0, pixels[i-1] - 20) / 2));
77+
Serial.print(charPixels[val]);
78+
if (i % 8 == 0)
79+
Serial.println();
80+
}
81+
Serial.println();
82+
#endif
83+
#if SERIAL_OUT == 3 || SERIAL_OUT == 2
84+
// Print coordinates and brightness
85+
Serial.print(x);
86+
Serial.print(' ');
87+
Serial.print(y);
88+
Serial.print(' ');
89+
Serial.println(magnitude);
90+
#endif
91+
}
92+
93+
/*
94+
void loop() {
95+
// Read all the pixels
96+
97+
// Find the focal point.
98+
float x, y, magnitude;
99+
find_focus(x, y, magnitude);
100+
101+
// Set diagnostic LEDs.
102+
analogWrite(CENTER_LED, round(max(0, magnitude / 30) * 255));
103+
analogWrite(RIGHT_LED, round(min(1.0, max(0.0, -x / 3)) * 255));
104+
analogWrite(LEFT_LED, round(min(1.0, max(0.0, x / 3)) * 255));
105+
analogWrite(UP_LED, round(min(1.0, max(0.0, y / 3)) * 255));
106+
analogWrite(DOWN_LED, round(min(1.0, max(0.0, -y / 3)) * 255));
107+
108+
delay(200);
109+
}
110+
*/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* Read the IR sensor and try to figure out where the heat is located.
2+
3+
Orientation: Looking into the sensor, the window is on the bottom of the silver package,
4+
and the Adafruit star is at the upper left.
5+
X goes from about -1.0 on the left, facing out of the sensor, to +1.0 on the right.
6+
Y goes roughly from -1.0 (less?) on the bottom to +1.0 on the top.
7+
The sensor is oriented with its text upside down for the moment.
8+
Magnitude is currently the maximum temperature of any pixel, in degrees C.
9+
*/
10+
11+
class HeatSensor {
12+
public:
13+
// The current focus position, each from -1.0 .. +1.0.
14+
float x, y;
15+
16+
// The current magnitude estimate, in degrees C.
17+
float magnitude;
18+
19+
// Must be called once.
20+
void setup();
21+
22+
// Reads the sensor and updates x, y, and magnitude.
23+
void find_focus();
24+
};
1 MB
Binary file not shown.

0 commit comments

Comments
 (0)