// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// Verkehrshaus mit 1 Bildschirm: TFT DISPLAY
// =============================
// SPI displays: works with TFT display 240x320
//
// Hardware: ESP32-S3 44pin,
// Display: TFT display 240x320 SPI
// Libraries: Adafruit_ILI9341.h (TFT)
// Processor: Selection in Arduino IDE: ESP32S3 Dev Module
// Possible Touch Pins for ESP32S3 44pin: GPIO #: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Possible Output Pins for ESP32S3 44pin: GPIO #: 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 46
// 0 1 2 19 20 21 35 36 37 38 39 40 41 42 43 44 45 47 48 48 (or38?): internal RGB LED
// to be added:
// -
// -
// last: 30.01.24 Jan.2024
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
// TFT ILI9341 Full color 240x320 2.8" LCD-TFT display with SPI interface and touch screen (resistive, needs stylo)
// # Name======Description===========ESP32S3/44==ESP32_urish==Arduino Uno============
// 1 VCC Supply voltage 5V 5V 5V
// 2 GND Ground GND GND GND
// 3 CS SS Chip/Slave select 10 15 10† † You connect CS and D/C to any digital Arduino pin. The pin numbers here are just an example.
// 4 RST Reset* 13 4 (8)- * The RST and backlight (LED) pins are not available in the simulation.
// 5 D/C DC Data/command 14 2 9† † You connect CS and D/C to any digital Arduino pin. The pin numbers here are just an example.
// 6 MOSI SDI DIN data (MCU→LCD) 11 23 11
// 7 SCK CLK clock 12 18 13
// 8 LED Backlight LED* - - 5V * The RST and backlight (LED) pins are not available in the simulation.
// 9 MISO SDO SPI data (LCD→MCU)‡ - (9?) 19 12 ‡ You can leave MISO disconnected, unless you need to read data back from the LCD.
// Touch-pins:
// 10 T_CLK identical with SCK
// 11 T_CS needs own pin, e.g. 7 für Arduino Uno CS SS (slave select touch)
// 12 T_DIN identical with MOSI SDI DIN
// 13 T_DO identical with MISO SDO
// 14 T_IRQ - unassigned
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//
// 1D arrays int array1D[5] = { 1, 2, 3, 4, 5 }; table with one row named 'array1D'
// 2D arrays int array2D[2][3] = { { 1, 2, 3}, { 4, 5, 6} }; table with two rows, three columns, named 'array2D'
// 3D arrays int array3D[2][2][3] = {{ { 1, 2, 3}, { 4, 5, 6} }, two tables with each two rows and three columns
// { { 7, 8, 9}, {10,11,12} }};
//
// for i=0; 1<5; i++) print the whole content of the 1D array
// { printf("%d ", array1D[i]); }
//
// for (i=0; i<2; i++) print the whole content of the 2D array
// { for(j=0; j<3; j++)
// { printf("%d ", array2D[i][j]);
// }
// }
//
// for (i=0; i<2; i++) print the whole content of the 3D array
// { for(j=0; j<2; j++)
// { for(k=0; k<3; k++)
// { printf("%d ", array3D[i][j][k]);
// }
// }
// }
//
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// **************************************************************************************************
// D E F I N I T I O N S *
// **************************************************************************************************
#include "Adafruit_ILI9341.h" // library for TFT display with ILI9341
#include "Adafruit_GFX.h" // needed? Core graphics library
// ===== CONSTRUCTOR in Wokwi apparently needs Hardware pins 11 (data) and 12 (clock) and 13 (RST), CS and DC can be defined, LED and MISO unconnected
#define CS 10 // CS chipsel pin# std.S3 10 (ESP32 5)
#define DC 14 // DC datcom pin# std.S3 14 (ESP32 2)
Adafruit_ILI9341 TFT = Adafruit_ILI9341(CS, DC); // Hardware Constructor for TFT ILI9341 Full color 240x320 2.8" display with SPI interface
// ===== CONSTRUCTOR might need ESP32s3/44p Hardware pins 11 (data) / 12 (clock) / 13 (RST), CS and DC can be defined, LED and MISO unconnected
//#define CS 10 // CS chipsel pin# std.S3 10 (ESP32 5)
//#define DC 14 // DC datcom pin# std.S3 14 (ESP32 2)
//#define MOSI 11 // MOSI data pin# std.S3 11 (ESP32 23)
//#define CLK 12 // CLK clock pin# std.S3 12 (ESP32 18)
//#define RST 13 // RST reset pin# std.S3 13 (ESP32 16)
//#define MISO -1? 3 ? // MISO unconnected or e.g. pin# std.S3 3 (ESP32 ?)
//Adafruit_ILI9341 TFT = Adafruit_ILI9341(CS, DC, MOSI, CLK, RST, MISO); // Software Constructor for TFT ILI9341
//Adafruit_ILI9341 TFT = Adafruit_ILI9341(CS, DC); // Hardware constructor (11 data) (12 clock) (13 RST)
const int buttonLang = 15; // language switching button
const int buttonOK = 3; // OK
const int ledPin = 5;
//int buttonState = 0; // starting value, button not pressed
//float cursor = 3.4321; // variable to play with...
int indexL = 0; // Language starting value for array position ("0" is first menu item, so "-1" will start with first menu name)
int indexQ = 0; // Question starting value for array position ("0" is first menu item)
int indexA = 4; // Answers starting value for array position ("0" is first menu item, answers start at 5th position -> so index 4)
String arrayL[4] = // arrayL for the languages
{
"Deutsch",
"English",
"Francais",
"Italiano"
};
float arrayCO2[5][5] = // impact values for the 5 answers to the 5 questions
{
{ 1, 2, 3, 4, 5 }, // Wohnen A..E
{ 6, 7, 8, 9, 10 }, // Ernährung A..E
{ 11, 12, 13, 14, 15 }, // Konsum A..E
{ 16, 17, 18, 19, 20 }, // Mobilitaet A..E
{ 21, 22, 23, 24, 25 } // Flug A..E
};
String arrayUI[4][4][3] = // User Interaction UI in 4 languages -> 4 tables with each 4 rows and 3 columns
{
{ { "WILLKOMMEN zum Gasometer" , "AUSWERTUNG" , "RESULTAT" }, // D Titel 1, Untertitel 4 / Titel 2 Untertitel 5 etc.
{ "Meine persoenlichen Klimagase" , "Neugierig?" , "dein CO2 Footprint:" },
{ "mit 5 Fragen erfasst" , "Wie hoch ist dein Fussabdruck?" , " " },
{ "BUTTON to switch language" , "Drücke AUSWERTUNG" , " " } },
{ { "WELCOME to the Gasometer" , "EVALUATE" , "RESULT" }, // E
{ "my personal climate gases" , "Curious?" , "your footprint:" },
{ "checked with 5 questions" , "What's your footprint?" , " " },
{ " " , "Press EVALUATE" , " " } },
{ { "BIENVENU au Gasometre" , "EVALUATION" , "RESULTAT" }, // F
{ "mon bilan personel du CO2" , "Curieux?" , "ton footprint:" },
{ "verifié avec 5 questions" , "Quel est ton footprint?" , " " },
{ " " , "Pousse EVALUER?" , " " } },
{ { "BENVENUTO al Gasometro" , "VALUTAZIONE" , "RISULTATO" }, // I
{ "mia impronta di carbonio personale" , "Curioso?" , "la tua impronta:" },
{ "verificato con 5 domande" , "Qual e la tua impronta?" , " " },
{ " " , "Stampa VALUTAZIONE" , " " } }
};
String arrayQA[4][9][5] = // Titles, 5 Questions and 5 Answers -> 4 tables with each 7 rows and 5 columns
{
{ { "WOHNEN" , "ESSEN" , "KONSUMIEREN" , "MOBILITAET" , "FLIEGEN" }, // D
{ "Meine Wohnsituation entspricht" , "Ich ernaehre mich" , "Ich achte beim Einkauf von Kleidern," , "Mein Mobilit\xE4tsverhalten" , "Mein Flugverhalten" },
{ "am ehesten:" , "hauptsaechlich..." , "Elektronik etc. auf die Herkunft und" , "entspricht am ehesten:" , "entspricht am ehesten:" },
{ " " , " " , "benutze die Sachen lange" , " " , " " },
{ "Wohnung neu mit W\xE4rmepumpe" , "vegan" , "trifft voll zu" , "kein Auto, Velo und \xD6V" , "nie" },
{ "Haus neu mit W\xE4rmepumpe" , "vegetarisch" , "meistens" , "Elektroauto" , "1x pro Jahr" },
{ "Wohnung Haus alt mit W\xE4rmepumpe" , "Flexitarier" , "manchmal" , "Auto Benzin/Diesel, wenig km" , "2x pro Jahr" },
{ "Wohnung mit Gas-/\xD6lheizung" , "'normal', einfach alles" , "ist mir nicht so wichtig" , "Auto Benzin/Diesel ca 15000 km/a" , "3-4x pro Jahr" },
{ "Haus mit Gas-/\xD6lheizung" , "fleischorientiert" , "ich liebe Shopping!" , "Auto Benzin/Diesel, Vielfahrer" , ">4x pro Jahr" } },
{ { "LIVING" , "EATING" , "CONSUMPTION" , "MOBILITY" , "FLYING" }, // E
{ "My living situation corresponds" , "I eat mainly" , "Buying clothes, electronics etc." , "My mobility behavior" , "My flying behavior" },
{ "most closely to:" , "like..." , "I'm looking for proveniance and" , "is most likely:" , "is most likely:" },
{ " " , " " , "I use my stuff for a long time" , " " , " " },
{ "Flat new with heatpump" , "vegan" , "fully true" , "no car, bicycle and public trsp" , "never" },
{ "House new with heatpump" , "vegetarian" , "mostly" , "electric car" , "1x per year" },
{ "Flat/house old with heatpump" , "flexitarien" , "sometimes" , "gas/diesel car, few km/a" , "2x per year" },
{ "Flat with gas/oil heating" , "'normal', simply everything" , "no so important to me" , "gas/diesel car, ~15000 km/a" , "3-4x per year" },
{ "House with gas/oil heating" , "I'm a little carnivor" , "I love Shopping!" , "gas/diesel car, frequent driver" , ">4x per year" } },
{ { "VIVRE" , "MANGER" , "CONSOMMER" , "MOBILITE" , "VOLER" }, // F
{ "Ma situation de logement" , "je me nourris principalement" , "Achetant des vêtements, électronique" , "mes habitudes de mobilité" , "mes vols annuels" },
{ "correspond le plus a..." , " " , "je fais attention à leur provenance" , "correspondent à peu près..." , "sont environ..." },
{ " " , " " , "et j'utilise les produits longtemps." , " " , " " },
{ "Flat new with heatpump" , "vegan" , "fully true" , "no car, bicycle and public trsp" , "never" },
{ "House new with heatpump" , "vegetarian" , "mostly" , "electric car" , "1x per year" },
{ "Flat/house old with heatpump" , "flexitarien" , "sometimes" , "gas/diesel car, few km/a" , "2x per year" },
{ "Flat with gas/oil heating" , "'normal', simply everything" , "no so important to me" , "gas/diesel car, ~15000 km/a" , "3-4x per year" },
{ "House with gas/oil heating" , "I'm a little carnivor" , "I love Shopping!" , "gas/diesel car, frequent driver" , ">4x per year" } },
{ { "VIVERE" , "MANGIARE" , "CONSUMARE" , "MOBILITA" , "VOLARE" }, // I
{ "la mia situazione abitativa" , "Mangio principalmente.." , "Quando compro vestiti, elettronica," , "il mio comportamento di mobilità" , "i miei voli annuali" },
{ "è approssimativamente:" , " " , "faccio attenzione all'origine e" , "corrisponde maggiormente a..." , "sono circa..." },
{ " " , " " , "uso i prodotti per molto tempo" , " " , " " },
{ "Flat new with heatpump" , "vegan" , "fully true" , "no car, bicycle and public trsp" , "never" },
{ "House new with heatpump" , "vegetarian" , "mostly" , "electric car" , "1x per year" },
{ "Flat/house old with heatpump" , "flexitarien" , "sometimes" , "gas/diesel car, few km/a" , "2x per year" },
{ "Flat with gas/oil heating" , "'normal', simply everything" , "no so important to me" , "gas/diesel car, ~15000 km/a" , "3-4x per year" },
{ "House with gas/oil heating" , "I'm a little carnivor" , "I love Shopping!" , "gas/diesel car, frequent driver" , ">4x per year" } },
};
//const int numCh = sizeof(arrayStation)/sizeof(char *); // ?
String language = arrayL[indexL];
// **************************************************************************************************
// F U N C T I O N S *
// **************************************************************************************************
// **************************************************************************************************
// S E T U P *
// **************************************************************************************************
void setup()
{
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(buttonLang, INPUT_PULLUP); // pin set HIGH, goes LOW if pressed
pinMode(buttonOK, INPUT_PULLUP); // pin set HIGH, goes LOW if pressed
TFT.begin(); // TFT begin TFT display ILI9341 Full color 240x320 2.8" SPI
TFT.setRotation(1); // vertical (0), horizontal (1), vertical down (2), horizontal down (3), vertical (4)
TFT.fillScreen(ILI9341_BLACK); // screen color standard: TFT.fillScreen(ILI9341_BLACK); BLUE, WHITE, ...
TFT.setCursor(0, 10);
TFT.setTextColor(ILI9341_WHITE);
TFT.setTextSize(2);
TFT.println(arrayUI[indexL][0][0]); // WILLKOMMEN Startsprache D (indexL = 0 vordefiniert)
TFT.println(arrayUI[indexL][1][0]);
TFT.println(arrayUI[indexL][2][0]);
TFT.setCursor(0, 200);
TFT.println(arrayUI[indexL][3][0]); // BUTTON für Sprachauswahl
delay(2000);
//TFT.fillScreen(ILI9341_GREEN); // screen color standard: TFT.fillScreen(ILI9341_BLACK); BLUE, WHITE, ...
//delay(100);
}
// **************************************************************************************************
// L O O P *
// **************************************************************************************************
void loop()
{
if (digitalRead(buttonLang) == LOW) // Button defined as INPUT_PULLUP, LOW means pressed
{
indexL = (indexL + 1); // raise index (language#) by 1
//indexPointer = (indexPointer + 1) % numCh; // raise indexPointer by 1 % modulo numCh?
if (indexL > 3) // ... if over 3, then...
{ indexL = 0; } // ... set to 0, restart at top of array
language = arrayL[indexL]; // language gets next language name
TFT.fillScreen(ILI9341_BLACK); // screen color standard: TFT.fillScreen(ILI9341_BLACK); BLUE, WHITE, ...
TFT.setTextColor(ILI9341_WHITE);
TFT.setTextSize(3);
TFT.setCursor(0, 0);
TFT.println("BUTTON: D>E>F>I");
TFT.setTextColor(ILI9341_GREEN); // ILI9342_RED, ...GREEN, ... WHITE
TFT.setTextSize(2);
TFT.setCursor(0, 50);
TFT.println(arrayL[indexL]);
TFT.setCursor(300, 220);
TFT.println(indexL);
//delay(500);
}
//if (!digitalRead(buttonOK) == LOW) // Button defined as INPUT_PULLUP, LOW means pressed
//{}
TFT.setTextColor(ILI9341_WHITE);
TFT.setTextSize(1);
TFT.setCursor(10, 200);
TFT.println(arrayUI[indexL][2][4]);
//delay(1000);
//TFT.fillScreen(ILI9341_BLUE); // screen color standard: TFT.fillScreen(ILI9341_BLACK); BLUE, WHITE, ...
TFT.setTextColor(ILI9341_WHITE);
TFT.setTextSize(2);
TFT.setCursor(0, 100);
TFT.println(arrayQA[indexL][1][1]); // Frage Bsp. "ich ernähre mich"
TFT.setCursor(0, 150);
TFT.println(arrayQA[indexL][6][1]); // ANtwort Bsp. "Flexitarier"
}