/*
ESP32 HTTPClient Jokes API Example
https://wokwi.com/projects/342032431249883731
Copyright (C) 2022, Uri Shaked
*/
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS_1 21
#define ONE_WIRE_BUS_2 22
OneWire oneWire1(ONE_WIRE_BUS_1);
OneWire oneWire2(ONE_WIRE_BUS_2);
DallasTemperature sensors1(&oneWire1);
DallasTemperature sensors2(&oneWire2);
#define SWITCH_PIN 32 // Pin untuk tombol sakelar
#define BTN_PIN 5
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
String text;
unsigned int i, j, w, h;
float tempC1, tempC2, tempC3, tempC4;
unsigned long startTime = 0;
unsigned long stopTime = 0; // Waktu ketika stopwatch dihentikan
bool isRunning = false;
bool lastButtonState = HIGH; // Untuk menyimpan status terakhir tombol
void setup(void) {
Serial.begin(9600);
sensors1.begin();
sensors2.begin();
pinMode(SWITCH_PIN, INPUT_PULLUP); // Mengatur pin sakelar sebagai input dengan resistor pull-up internal
uint16_t ID = 0x9488;
Serial.print("ID = 0x");
Serial.println(ID, HEX);
tft.begin();
tft.setRotation(1);
tft.fillScreen(BLACK);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.fillScreen(BLACK);
tft.drawRect(0, 0, 320, 240, GREEN);
tft.setTextSize(3);
tft. setTextColor(CYAN);
getTextBounds("Universitas", 3);
tft.setCursor((320 - w) / 2, 30);
tft.println("Universitas");
getTextBounds("Maritim", 3);
tft.setCursor((320 - w) / 2, 80);
tft.println("Maritim");
getTextBounds("Raja Ali Haji", 3);
tft.setCursor((320 - w) / 2, 130);
tft.println("Raja Ali Haji");
getTextBounds("2024", 3);
tft.setCursor((320 - w) / 2, 180);
tft.println("2024");
delay(2000);
tft.fillScreen(BLACK);
tft.drawRect(0, 0, 320, 240, GREEN);
tft.setTextColor(YELLOW);
tft.setTextSize(3);
getTextBounds("ALAT", 3);
tft.setCursor((320 - w) / 2, 30);
tft.println("ALAT");
getTextBounds("PENGUKUR", 3);
tft.setCursor((320 - w) / 2, 80);
tft.println("PENGUKUR");
getTextBounds("SUHU BATERAI", 3);
tft.setCursor((320 - w) / 2, 130);
tft.println("SUHU BATERAI");
tft. setTextColor(WHITE);
getTextBounds("GANDHI RIZKY", 3);
tft.setCursor((320 - w) / 2, 180);
tft.println("GANDHI RIZKY");
delay(1000);
tft.fillScreen(BLACK);
}
void loop() {
unsigned long waktu = millis();
bool currentButtonState = digitalRead(SWITCH_PIN);
if (digitalRead(32) == LOW && isRunning==0) { // Assuming switch button is connected to pin SWITCH_PIN
isRunning = true;
startTime = millis();
}
if (currentButtonState == HIGH && lastButtonState == LOW && isRunning) {
isRunning = false;
stopTime = millis();
}
lastButtonState = currentButtonState;
sensors1.requestTemperatures();
sensors2.requestTemperatures();
tft.fillScreen(BLACK);
// tft.drawRoundRect(0, 20, 320, 240, 5, CYAN);
tft.drawRoundRect(0, 50, 310, 40,5,CYAN);
tft.drawRoundRect(0, 90, 310, 40, 5,CYAN);
tft.drawRoundRect(0, 140, 310, 40,5, CYAN);
tft.drawRoundRect(0, 180, 310, 40,5, CYAN);
tft.setTextColor(GREEN);
tft.setCursor(40, 60);
tft. setTextSize(3);
tft.print("Suhu1");
tft.print(": ");
tft.print(tempC1);
tft.println("C");
tft.setCursor(40, 100);
tft.print("Suhu2");
tft.print(": ");
tft.print(tempC2);
tft.println("C");
tft.setCursor(40, 150);
tft.print("Suhu3");
tft.print(": ");
tft.print(tempC3);
tft.println("C");
tft.setCursor(40, 190);
tft.print("Suhu4");
tft.print(": ");
tft.print(tempC4);
tft.println("C");
if (isRunning) {
unsigned long currentTime = millis();
unsigned long elapsedTime = currentTime - startTime;
unsigned long hours = elapsedTime / 3600000;
unsigned long minutes = (elapsedTime / 60000) % 60;
unsigned long seconds = (elapsedTime / 1000) % 60;
tft.setCursor(100, 3);
tft.setTextSize(2);
if (hours < 10) tft.print("0");
tft.print(hours);
tft.print(":");
if (minutes < 10) tft.print("0");
tft.print(minutes);
tft.print(":");
if (seconds < 10) tft.print("0");
tft.print(seconds);
}
else {
unsigned long stoppedTime = stopTime - startTime;
unsigned long hours = stoppedTime / 3600000;
unsigned long minutes = (stoppedTime / 60000) % 60;
unsigned long seconds = (stoppedTime / 1000) % 60;
tft.setCursor(100, 20);
tft.setTextSize(2);
if (hours < 10) tft.print("0");
tft.print(hours);
tft.print(":");
if (minutes < 10) tft.print("0");
tft.print(minutes);
tft.print(":");
if (seconds < 10) tft.print("0");
tft.print(seconds);
}
while (millis() - waktu < 1000);
}
void getTextBounds(String Str, byte sizes) {
int widths = 6;
int heights = 8;
unsigned int jumlahKarakter = Str.length();
w = (jumlahKarakter) * 6 * sizes;
h = 8 * sizes;
}Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20
Loading
ds18b20
ds18b20