mvp
This commit is contained in:
57
dnddice.ino
57
dnddice.ino
@@ -1,6 +1,7 @@
|
||||
#include <TFT_eSPI.h>
|
||||
#include "esp_adc_cal.h"
|
||||
#include "Button2.h"
|
||||
#include "animation.h"
|
||||
#include "dndlogo.h"
|
||||
|
||||
#define ADC_EN 14 //ADC_EN is the ADC detection enable port
|
||||
@@ -13,8 +14,9 @@ Button2 btn1(BUTTON_1);
|
||||
Button2 btn2(BUTTON_2);
|
||||
|
||||
// MENU
|
||||
byte menuItems[] = {20, 12, 10, 8, 6, 4, 3, 2};
|
||||
byte menuItems[] = { 20, 12, 10, 8, 6, 4, 3, 2 };
|
||||
byte menuPosition = 0;
|
||||
int menuHeight = 20;
|
||||
int num_items = sizeof(menuItems) / sizeof(byte);
|
||||
|
||||
String temp;
|
||||
@@ -51,8 +53,7 @@ void showVoltage()
|
||||
uint16_t v = analogRead(ADC_PIN);
|
||||
float battery_voltage = ((float)v / 4095.0) * 2.0 * 3.3 * (vref / 1000.0);
|
||||
String voltage = "Voltage :" + String(battery_voltage) + "V";
|
||||
Serial.println(voltage);
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextDatum(BL_DATUM);
|
||||
tft.drawString(voltage, tft.width() / 1.5, tft.height());
|
||||
}
|
||||
@@ -60,11 +61,19 @@ void showVoltage()
|
||||
|
||||
void throwDice()
|
||||
{
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
drawMenu();
|
||||
randomSeed(analogRead(1));
|
||||
int dice = menuItems[menuPosition];
|
||||
int number = random(dice) + 1;
|
||||
tft.setTextPadding(tft.width());
|
||||
tft.setTextDatum(BL_DATUM);
|
||||
tft.drawString(String(number), tft.width() / 1.5, tft.height());
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
tft.setTextSize(6);
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
tft.setTextPadding(tft.height());
|
||||
tft.drawString(String(number), tft.width() / 2, (tft.height() / 2) + (menuHeight / 2));
|
||||
espDelay(1000);
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
drawMenu();
|
||||
}
|
||||
|
||||
void drawMenu()
|
||||
@@ -72,13 +81,13 @@ void drawMenu()
|
||||
tft.fillScreen(TFT_BLACK);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
tft.setTextSize(2);
|
||||
tft.drawRect(0, 20, TFT_HEIGHT, 1, TFT_WHITE);
|
||||
tft.drawRect(0, menuHeight, TFT_HEIGHT, 1, TFT_WHITE);
|
||||
|
||||
int boxWidth = round(tft.width() / num_items);
|
||||
|
||||
for (int i = 1; i <= num_items; i++)
|
||||
{
|
||||
tft.drawFastVLine(i * boxWidth, 0, 20, TFT_WHITE);
|
||||
tft.drawFastVLine(i * boxWidth, 0, menuHeight, TFT_WHITE);
|
||||
tft.setTextColor(TFT_WHITE, TFT_BLACK);
|
||||
tft.setTextSize(2);
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
@@ -95,8 +104,8 @@ void drawSelectedMenu()
|
||||
{
|
||||
int boxWidth = round(tft.width() / num_items);
|
||||
|
||||
tft.drawRect(menuPosition * boxWidth, 0, boxWidth, 20, TFT_WHITE);
|
||||
tft.fillRect(menuPosition * boxWidth, 0, boxWidth, 20, TFT_WHITE);
|
||||
tft.drawRect(menuPosition * boxWidth, 0, boxWidth, menuHeight, TFT_WHITE);
|
||||
tft.fillRect(menuPosition * boxWidth, 0, boxWidth, menuHeight, TFT_WHITE);
|
||||
|
||||
tft.setTextColor(TFT_BLACK, TFT_WHITE);
|
||||
tft.setTextDatum(MC_DATUM);
|
||||
@@ -140,21 +149,21 @@ void button_init()
|
||||
// clearScreen();
|
||||
// drawMenu();
|
||||
// });
|
||||
btn1.setPressedHandler([](Button2 &b)
|
||||
{
|
||||
throwDice();
|
||||
espDelay(1000);
|
||||
});
|
||||
btn1.setPressedHandler([](Button2& b)
|
||||
{
|
||||
throwDice();
|
||||
espDelay(1000);
|
||||
});
|
||||
|
||||
btn2.setPressedHandler([](Button2 &b)
|
||||
{
|
||||
menuPosition++;
|
||||
menuPosition = menuPosition++ % num_items;
|
||||
drawMenu();
|
||||
drawSelectedDice();
|
||||
espDelay(1000);
|
||||
clearScreen();
|
||||
});
|
||||
btn2.setPressedHandler([](Button2& b)
|
||||
{
|
||||
menuPosition++;
|
||||
menuPosition = menuPosition++ % num_items;
|
||||
drawMenu();
|
||||
// drawSelectedDice();
|
||||
// espDelay(1000);
|
||||
clearScreen();
|
||||
});
|
||||
}
|
||||
|
||||
void button_loop()
|
||||
|
||||
Reference in New Issue
Block a user