Ian Teodoro, Evelynn Li, Anne Fernandez
After a bit of a rocky start during the ideating phase, we
finished this quarter off with a playful project that allows users to see the
emotions of their plant – Bud.
Video: https://drive.google.com/file/d/1b1eK4uO0vhyuOCsTPBKznY8S0KF_D0U-/view?usp=sharing
Resources:
https://www.instructables.com/Plant-Moisture-Sensor-W-Arduino/
https://create.arduino.cc/projecthub/projects/tags/plants
Code:
#include "Adafruit_GFX.h" // Core graphics library
#include "MCUFRIEND_kbv.h" // Hardware-specific library
MCUFRIEND_kbv tft;
#include "face.h"
#define BLACK 0x0000
#define WHITE 0xFFFF
int sensorPin = A5;
float sensorValue = 0;
int readVal;
int faceState;
void setup() {
Serial.begin(9600);
uint16_t ID = tft.readID();
tft.begin(ID);
tft.setRotation(1);
tft.fillScreen(WHITE);
pinMode (sensorPin, INPUT);
pinMode (happy, OUTPUT);
pinMode (neutral, OUTPUT);
pinMode (sad, OUTPUT);
pinMode (mad, OUTPUT);
pinMode (dead, OUTPUT);
//moisture
for (int i = 0; i <= 100; i++)
{
sensorValue = sensorValue + analogRead(sensorPin);
delay(1);
}
sensorValue = sensorValue/100.0;
Serial.println(sensorValue);
delay(1000);
}
void happy () {
tft.fillScreen(WHITE);
tft.drawBitmap(119, 200, myBitmapface_happy, 248, 73, BLACK);
}
void neutral () {
tft.fillScreen(WHITE);
tft.drawBitmap(119, 211,myBitmapface_neutral, 248, 42, BLACK);
}
void sad () {
tft.fillScreen(WHITE);
tft.drawBitmap(119, 211,myBitmapface_sad, 250, 69, BLACK);
}
void mad () {
tft.fillScreen(WHITE);
tft.drawBitmap(119, 211,myBitmapface_mad, 248, 89, BLACK);
}
void dead () {
tft.fillScreen(WHITE);
tft.drawBitmap(119, 211,myBitmapface_dead, 242, 69, BLACK);
}
void loop() {
readVal=analogRead(sensorPin);
if ((readVal<=1)&&(faceState!=0)) {
dead();
faceState = 0;
}
else if ((readVal>1 && readVal <=80)&&(faceState!=1)) {
mad();
faceState = 1;
}
else if ((readVal>80 && readVal <=120)&&(faceState!=2)) {
sad();
faceState = 2;
}
else if ((readVal>120 && readVal <=160)&&(faceState!=3))
{
neutral();
faceState = 3;
}
else if ((readVal>200 && readVal <=250)&&(faceState!=4))
{
happy();
faceState = 4;
}
}
No comments:
Post a Comment