#include "C:/Users/FSmilari/Documents/Arduino/libraries/Adafruit_GFX_Library/Adafruit_GFX.h" // Include core graphics library #include "D:/Programme/sloeber/4.4/arduinoPlugin/libraries/Adafruit_ST7735_and_ST7789_Library/1.11.0/Adafruit_ST7735.h" // Include Adafruit_ST7735 library to drive the display #include "D:/Programme/sloeber/4.4/arduinoPlugin/packages/arduino/hardware/avr/1.8.4/cores/arduino/Arduino.h" #include "D:/Programme/sloeber/4.4/arduinoPlugin/packages/arduino/hardware/avr/1.8.4/cores/arduino/HardwareSerial.h" #include "D:/Programme/sloeber/4.4/arduinoPlugin/packages/arduino/hardware/avr/1.8.4/cores/arduino/WString.h" #include "D:/Programme/sloeber/4.4/arduinoPlugin/packages/arduino/hardware/avr/1.8.4/variants/standard/pins_arduino.h" #include "ExEzButton.h" #include "Status.h" #include "fonts/titillium_web_regular20pt7b.h" // Add a custom font #include "images/SFToolsLogo.h" #include "images/thermometer_32.h" #include "RotaryControler.h" static const int RotEnc_Switch_Pin = 3; static const int RotEnc_Clk_Pin = 4; static const int RotEnc_Dta_Pin = 5; static const int Measure_Pin = 6; static const int echoPin = A5; static const int trigPin = A4; #define LED -1 // to +5v #define SCK 13//A1 with SCK on 13 and SDA on 11 it is 10x faster!!! #define SDA 11//A2 #define MISO -1 #define MOSI SDA #define CS 10 #define DC 9 #define RST 8 Status actualStatus; Status originStatus; String oldStatus = ""; String lastDistance = ""; // Create display: Adafruit_ST7735 tft = Adafruit_ST7735(CS, DC, RST); RotaryControler RotaryControler(RotEnc_Dta_Pin, RotEnc_Clk_Pin, RotEnc_Switch_Pin); ExEzButton MeasureBtn(Measure_Pin, false, 2000); void setup() { SetActualStatus(INITIALIZATION); Serial.begin(115200); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(Measure_Pin, INPUT); pinMode(RotEnc_Switch_Pin, INPUT); MeasureBtn.setDebounceTime(50); RotaryControler.setDebounceTime(50); // Display setup: // Use this initializer if you're using a 1.8" TFT tft.initR(INITR_BLACKTAB); // Initialize a ST7735S chip, black tab tft.fillScreen(ST7735_BLACK); // Fill screen with black tft.setRotation(2); // Set orientation of the display. Values are from 0 to 3. If not declared, orientation would be 0, // which is portrait mode. tft.setTextWrap(false); // By default, long lines of text are set to automatically “wrap� back to the leftmost column. // To override this behavior (so text will run off the right side of the display - useful for // scrolling marquee effects), use setTextWrap(false). The normal wrapping behavior is restored // with setTextWrap(true). tft.setCursor(0, 20); // Set position (x,y) tft.setFont(&titillium_web_regular20pt7b); tft.setTextSize(0); // Set text size. Goes from 0 (the smallest) to 20 (very big) tft.setTextColor(ST7735_WHITE); tft.println("Hello"); tft.drawBitmap(0, 80, SFTools_Logo, 128, 34, ST7735_GREEN); tft.drawBitmap(1, 160 - 32, thermometer_icon_32, 32, 32, 0xE71C); tft.drawBitmap(33, 160 - 32, thermometer_icon_32, 32, 32, ST7735_YELLOW); tft.drawRect(48, 137, 2, 6, ST7735_YELLOW); tft.drawBitmap(65, 160 - 32, thermometer_icon_32, 32, 32, ST7735_RED); tft.drawRect(80, 133, 2, 10, ST7735_RED); delay(3000); tft.fillScreen(ST7735_BLACK); // Fill screen with black } void loop() { MeasureBtn.loop(); RotaryControler.loop(); switch (actualStatus) { case INITIALIZATION: SetActualStatus(IDLE); break; case CONFIGURATION: break; case IDLE: if (RotaryControler.isSwitchPressed()) { Serial.println("RotaryEnc SwitchPressed"); } if (MeasureBtn.isPressing()) { digitalWrite(trigPin, LOW); delayMicroseconds(5); digitalWrite(trigPin, HIGH); delayMicroseconds(20); digitalWrite(trigPin, LOW); long duration = pulseIn(echoPin, HIGH); long distance = duration * 0.03432 / 2; Serial.print("Distance:"); Serial.println(distance); char buf[50]; sprintf(buf, "%lu cm", distance); if (!lastDistance.equals(buf)) { tft.fillRect(0, 20, 130, 50, ST7735_BLACK); tft.setCursor(0, 50); // Set position (x,y) tft.setFont(&titillium_web_regular20pt7b); tft.setTextSize(0); // Set text size. Goes from 0 (the smallest) to 20 (very big) tft.setTextColor(ST7735_CYAN); tft.println(buf); lastDistance = buf; } delay(200); // } else { // mylcd.Fill_Screen(BLACK); } break; case MEASURING: break; default: break; } } void SetActualStatus(Status newStatus) { if (actualStatus != newStatus) { actualStatus = newStatus; // Display.setRefreshScreen(); } }