#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC PB7
#define TFT_CS PB6
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int flow=20;
int press=100;
int valve=100;
int counter=0;
byte on = 0;
byte gpm = 0;
void setup() {
pinMode(A0, INPUT_PULLUP);
pinMode(A1, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(A3, INPUT_PULLUP);
tft.begin();
tft.setTextColor(ILI9341_CYAN);
tft.setTextSize(2);
tft.setCursor(0, 30);
tft.print(" Flow : ");
int temp = flow * 26;
tft.print(temp/100);
tft.print(".");
tft.print(temp/10);
tft.print(temp%10);
//tft.print(flow*26);
tft.println(" GPM");
tft.println();
tft.setTextColor(ILI9341_GREEN);
tft.setCursor(0, 60);
tft.print(" Pressure: ");
tft.print(press);
tft.println(" psi");
tft.println();
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(0, 90);
tft.print(" Valve : ");
tft.print(valve);
tft.println(" %");
tft.fillCircle(120, 200, 40, ILI9341_WHITE);
tft.fillCircle(120, 200, 35, ILI9341_RED);
tft.setCursor(105, 195);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
}
void loop() {
delay(1);
counter++;
if (counter==1000){
tft.setTextColor(ILI9341_GREEN,ILI9341_BLACK);
tft.setCursor(132, 60);
press = analogRead(PA4);
//press = map(press,0,4095,0,3300);
//press = map(press,580,2900,0,100);
//tft.print(press*145/100);
tft.print(press);
counter=0;
}
if ((digitalRead(A0)==0) && (on==0)){
tft.fillCircle(120, 200, 35, ILI9341_GREEN);
tft.setCursor(110, 195);
tft.setTextColor(ILI9341_BLACK);
tft.print("ON");
on=1;
while (digitalRead(A0)==0) delay(10);
}
else if ((digitalRead(A0)==0) && (on==1)){
tft.fillCircle(120, 200, 35, ILI9341_RED);
tft.setCursor(105, 195);
tft.setTextColor(ILI9341_BLACK);
tft.print("OFF");
on=0;
while (digitalRead(A0)==0) delay(10);
}
if (digitalRead(A1)==0){
tft.setTextColor(ILI9341_WHITE,ILI9341_BLACK);
tft.setCursor(132, 90);
if (valve>0) valve -= 10;
tft.print(valve);
tft.print(" % ");
while (digitalRead(A1)==0) delay(10);
}
if (digitalRead(A2)==0){
tft.setTextColor(ILI9341_WHITE,ILI9341_BLACK);
tft.setCursor(132, 90);
if (valve<90) valve += 10;
tft.print(valve);
tft.print(" % ");
while (digitalRead(A2)==0) delay(10);
}
if ((digitalRead(A3)==0) && (gpm==0)){
tft.setTextColor(ILI9341_CYAN,ILI9341_BLACK);
tft.setCursor(180, 30);
tft.print("GPM");
gpm=1;
while (digitalRead(A0)==0) delay(10);
}
else if ((digitalRead(A3)==0) && (gpm==1)){
tft.setTextColor(ILI9341_CYAN,ILI9341_BLACK);
tft.setCursor(180, 30);
tft.print("LPM");
gpm=0;
while (digitalRead(A0)==0) delay(10);
}
}Loading
stm32-bluepill
stm32-bluepill