Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
M5StickC Plus + GridEye
#include <M5StickCPlus.h>
#include <Wire.h>
#include <SparkFun_GridEYE_Arduino_Library.h>
GridEYE grideye;
void setup() {
// put your setup code here, to run once:
M5.begin();
Wire.begin(0,26);
M5.Lcd.println("Hello, world!");
grideye.begin();
}
const float TEMP_COLOR_S = 255;
const float TEMP_COLOR_V = 255;
const float TEMP_COLOR_MAX = 35;
const float TEMP_COLOR_MIN = 20;
uint16_t temp2color(float temp) {
float scaled = (temp - TEMP_COLOR_MIN) * (350 / (TEMP_COLOR_MAX - TEMP_COLOR_MIN));
if (scaled < 0) {
scaled = 0;
} else if (scaled > 350) {
scaled = 350;
}
float color_s = TEMP_COLOR_S;
float color_v = TEMP_COLOR_V;
float color_h = 240 - scaled;
while (color_h < 0) {
color_h += 360;
}
while (color_h > 360) {
color_h -= 360;
}
float color_max = color_v;
float color_min = color_max - ((color_s / 255) * color_max);
float color_diff = color_max - color_min;
uint16_t color;
if (color_h < 60) {
color = M5.Lcd.color565(
color_max,
(color_h/60)*color_diff + color_min,
color_min
);
} else if (color_h < 120) {
color = M5.Lcd.color565(
((120 - color_h)/60)*color_diff + color_min,
color_max,
color_min
);
} else if (color_h < 180) {
color = M5.Lcd.color565(
color_min,
color_max,
((color_h - 120)/60)*color_diff + color_min
);
} else if (color_h < 240) {
color = M5.Lcd.color565(
color_min,
((240 - color_h)/60)*color_diff + color_min,
color_max
);
} else if (color_h < 300) {
color = M5.Lcd.color565(
((color_h - 240)/60)*color_diff + color_min,
color_min,
color_max
);
} else {
color = M5.Lcd.color565(
color_max,
color_min,
((360 - color_h)/60)*color_diff + color_min
);
}
//Serial.printf("temp: %.2f scaled: %.2f color_h: %.2f color: %04x\n", temp, scaled, color_h, color);
return color;
}
void loop() {
// put your main code here, to run repeatedly:
//M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0,0);
//M5.Lcd.printf("Device temp: %f\n", grideye.getDeviceTemperature());
float temp_data[64];
float max_temp = -100;
float min_temp = 100;
for (unsigned short int i = 0; i < 64; i++) {
temp_data[i] = grideye.getPixelTemperature(i);
max_temp = temp_data[i] > max_temp ? temp_data[i] : max_temp;
min_temp = temp_data[i] < min_temp ? temp_data[i] : min_temp;
}
TFT_eSprite img = TFT_eSprite(&M5.Lcd);
img.createSprite(128, 128+30);
img.printf("Device temp: %.2f\n", grideye.getDeviceTemperature());
img.printf("Maximum temp: %.2f\n", max_temp);
img.printf("Minimum temp: %.2f\n", min_temp);
for (unsigned short int i = 0; i < 8; i++) {
for (unsigned short int j = 0; j < 8; j++) {
uint16_t color = temp2color(temp_data[i*8 + j]);
img.fillRect(i*16, j*16 + 30, 16, 16, color);
}
//M5.Lcd.printf("Pixel %d: %f\n", i, temp_data[i]);
}
img.pushSprite(0, 20);
img.deleteSprite();
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.