|
|
@ -12,21 +12,18 @@ |
|
|
|
driver: |
|
|
|
#define ST7735_DRIVER |
|
|
|
*/ |
|
|
|
|
|
|
|
#include <TFT_eSPI.h> // Hardware-specific library |
|
|
|
#include <SPI.h> |
|
|
|
|
|
|
|
#include <PNGdec.h> |
|
|
|
#include "icon_clown.h" // Image is stored here in an 8-bit array |
|
|
|
#include "soc/sens_reg.h" |
|
|
|
#include "TCP.h" |
|
|
|
|
|
|
|
#define potPin 13 // Potentiometer Pin
|
|
|
|
#define potPin 34 // Potentiometer Pin
|
|
|
|
#define MAX_IMAGE_WIDTH 240 // Adjust for your images
|
|
|
|
|
|
|
|
// Define some colors to match individual emotions
|
|
|
|
const uint16_t emotionColors[] = { |
|
|
|
0xFFE0, // HAPPY = YELLOW
|
|
|
|
0x001F, // SAD = BLUE
|
|
|
|
0x07E0, // SAD = BLUE
|
|
|
|
0xF800, // ANGRY = RED
|
|
|
|
0xFA60, // FEAR = ORANGE
|
|
|
|
0xF8FF, // SURPRISED = PURPLE
|
|
|
@ -44,61 +41,36 @@ enum Emotion { |
|
|
|
NEUTRAL |
|
|
|
}; |
|
|
|
|
|
|
|
float potData = 0; |
|
|
|
int past_prc_reading = 0; |
|
|
|
float deadband_val = 20; |
|
|
|
float pot_data = 0; |
|
|
|
Emotion emote; |
|
|
|
int screen_width, screen_height; |
|
|
|
// pass for beta: n->stubborn_vectors p->sv-beta24, and change IP address to server!
|
|
|
|
TCP tcp("VM9093853", "kfrzuk8UngxyytUz", "192.168.0.169", 12345); |
|
|
|
PNG png; |
|
|
|
TFT_eSPI tft = TFT_eSPI(); |
|
|
|
|
|
|
|
void pngDraw(PNGDRAW *pDraw) { |
|
|
|
uint16_t lineBuffer[MAX_IMAGE_WIDTH]; // Line buffer for rendering
|
|
|
|
uint8_t maskBuffer[1 + MAX_IMAGE_WIDTH / 8]; // Mask buffer
|
|
|
|
|
|
|
|
png.getLineAsRGB565(pDraw, lineBuffer, PNG_RGB565_BIG_ENDIAN, 0xffffffff); |
|
|
|
|
|
|
|
if (png.getAlphaMask(pDraw, maskBuffer, 255)) { |
|
|
|
// Note: pushMaskedImage is for pushing to the TFT and will not work pushing into a sprite
|
|
|
|
tft.pushMaskedImage(0, 0 + pDraw->y, pDraw->iWidth, 1, lineBuffer, maskBuffer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void setupWiFi(){ |
|
|
|
tcp.connectWiFi(tft); |
|
|
|
|
|
|
|
tcp.testConnection(); |
|
|
|
|
|
|
|
int emotionIndex = static_cast<int>(emote); |
|
|
|
tcp.sendData(potData, emotionIndex); |
|
|
|
} |
|
|
|
|
|
|
|
void drawImage(){ |
|
|
|
// Image sizes will be 128x128, a collection of 10~ per controller
|
|
|
|
uint16_t pngw = 0, pngh = 0; |
|
|
|
|
|
|
|
int16_t rc = png.openFLASH((uint8_t *)bob, sizeof(bob), pngDraw); |
|
|
|
|
|
|
|
if (rc == PNG_SUCCESS) { |
|
|
|
pngw = png.getWidth(); |
|
|
|
pngh = png.getHeight(); |
|
|
|
tft.startWrite(); |
|
|
|
rc = png.decode(NULL, 0); |
|
|
|
tft.endWrite(); |
|
|
|
} |
|
|
|
tcp.sendData(pot_data, emotionIndex); |
|
|
|
} |
|
|
|
|
|
|
|
void drawText(String& emotionText, int& i){ |
|
|
|
tft.drawCentreString(emotionText, screen_width / 2, 8, 1); |
|
|
|
|
|
|
|
float sinVal = sin(i * 0.05); // Sine output between -1 and 1
|
|
|
|
float mappedVal = (50 * sinVal) + 50; // Map it to between 1 and 100
|
|
|
|
String ps = String(mappedVal, 2); |
|
|
|
float mapped_val = i / 40.96f; |
|
|
|
mapped_val = floor(mapped_val); |
|
|
|
float dec_val = mapped_val / 100; |
|
|
|
String ps = String(mapped_val, 0); |
|
|
|
Serial.println(dec_val); |
|
|
|
ps.concat("%"); |
|
|
|
tft.drawCentreString(ps, screen_width / 2, screen_height - (screen_height / 6), 1); |
|
|
|
|
|
|
|
int emotionIndex = static_cast<int>(emote); |
|
|
|
tcp.sendData(mappedVal, emotionIndex); |
|
|
|
i++; |
|
|
|
tcp.sendData(dec_val, emotionIndex); |
|
|
|
} |
|
|
|
|
|
|
|
void setupEmotion(String& emotionText){ |
|
|
@ -117,10 +89,33 @@ void setupEmotion(String& emotionText){ |
|
|
|
tft.setTextSize(2); |
|
|
|
} |
|
|
|
|
|
|
|
int readSensor(int numSamples) { |
|
|
|
long sum = 0; |
|
|
|
|
|
|
|
for (int i = 0; i < numSamples; i++) { |
|
|
|
sum += analogRead(potPin); // Read the sensor
|
|
|
|
delay(5); // Small delay between samples
|
|
|
|
} |
|
|
|
|
|
|
|
int cur_avg_reading = sum / numSamples; |
|
|
|
|
|
|
|
if(abs(cur_avg_reading - past_prc_reading) > deadband_val){ |
|
|
|
past_prc_reading = cur_avg_reading; |
|
|
|
} |
|
|
|
|
|
|
|
return past_prc_reading; |
|
|
|
} |
|
|
|
|
|
|
|
// Function to get the next emotion
|
|
|
|
Emotion getNextEmotion(Emotion currentEmotion) { |
|
|
|
int nextEmotionIndex = (static_cast<int>(currentEmotion) + 1) % 7; // 7 is the number of emotions
|
|
|
|
return static_cast<Emotion>(nextEmotionIndex); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void setup(void) { |
|
|
|
// Set emotion
|
|
|
|
emote = Emotion::NEUTRAL; |
|
|
|
emote = Emotion::ANGRY; |
|
|
|
|
|
|
|
// Setup screen & serial
|
|
|
|
tft.init(); |
|
|
@ -140,19 +135,14 @@ void setup(void) { |
|
|
|
} |
|
|
|
|
|
|
|
void loop() { |
|
|
|
tft.setCursor(0, 0, 2); |
|
|
|
|
|
|
|
// Sin value
|
|
|
|
static int i = 0; |
|
|
|
unsigned long currentTime = millis(); |
|
|
|
|
|
|
|
// Display the emotion text
|
|
|
|
tft.setCursor(0, 0, 2); |
|
|
|
int x = readSensor(5); |
|
|
|
String emotionText; |
|
|
|
|
|
|
|
setupEmotion(emotionText); |
|
|
|
drawImage(); |
|
|
|
drawText(emotionText, i); |
|
|
|
|
|
|
|
delay(60); |
|
|
|
tcp.receiveImage(); |
|
|
|
drawText(emotionText, x); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|