/*##############################################################################
STM32 Blue Pill project using the STM32 Arduino Core (stm32duino)
Programm: Some aviation thing or so.
This program was created under the motto: I will make that myself.
[email protected]
##############################################################################*/
//Used library's
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "stm32f1xx_hal.h"
//Define Display connections
#define TFT_CS PB9
#define TFT_RST PB8
#define TFT_DC PB7
#define TFT_MOSI PB5
#define TFT_CLK PB3
#define TFT_LED PB6 //<-----Nog niet gebruikt
#define TFT_MISO PB4
//Define AngelEncoder connections
#define AngleEncoder_SW PB15
#define AngleEncoder_DT PB14
#define AngleEncoder_CLK PB13 //Dit is een Interupt pin
//Define LED connections
#define LED PB12
#define Button_LED PA0
#define Button PA0
//
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
/*
//Define colors B G R
#define Black tft.color565( 0, 0, 0) //BGR
#define Blue tft.color565(255, 0, 0) //BGR
#define Red tft.color565( 0, 0, 255) //BGR
#define Green tft.color565( 0, 255, 0) //BGR
#define Cyan tft.color565(255, 255, 0) //BGR
#define Magenta tft.color565(255, 0, 255) //BGR
#define Yellow tft.color565( 0, 255, 255) //BGR
#define DarkYellow tft.color565( 0, 128, 128) //BGR
#define White tft.color565(255, 255, 255) //BGR
#define Silver tft.color565(192, 192, 192) //BGR
#define DarkSilver tft.color565( 96, 96, 96) //BGR
*/
//Define colors R G B
#define Black tft.color565( 0, 0, 0) //RGB
#define Blue tft.color565( 0, 0, 255) //RGB
#define Red tft.color565(255, 0, 0) //RGB
#define Green tft.color565( 0, 255, 0) //RGB
#define Cyan tft.color565( 0, 255, 255) //RGB
#define Magenta tft.color565(255, 0, 255) //RGB
#define Yellow tft.color565(255, 255, 0) //RGB
#define DarkYellow tft.color565(128, 128, 0) //RGB
#define White tft.color565(255, 255, 255) //RGB
#define Silver tft.color565(192, 192, 192) //RGB
#define DarkSilver tft.color565( 96, 96, 96) //RGB
//Define variabelen
int BackGroundColor = Black;
int CompassOriginX = (tft.width() / 2);
int CompassOriginY = (tft.width() / 2); //Square compass
float SinVal;
float CosVal;
int Radius;
int Angle;
int OuterCircleColor = Silver;
int InnerCircleColor = Silver;
int CircelDistance = 20;
int X1;
int Y1;
int X2;
int Y2;
int X3;
int Y3;
int Color;
bool AngleLastClk;
void setup() {
Call_InitSerial();
Call_InitTFTscreen();
Call_InitAngleEncoder();
//Init AngleEncoder
pinMode(AngleEncoder_CLK, INPUT);
pinMode(AngleEncoder_DT, INPUT);
pinMode(AngleEncoder_SW, INPUT);
AngleLastClk = HIGH;
//attachInterrupt(digitalPinToInterrupt(AngleEncoder_CLK), ReadAngleEncoder, FALLING);
attachInterrupt(digitalPinToInterrupt(Button), ReadAngleEncoder, FALLING);
Call_InitPINmodes();
//Angle = 90 - 0; // Sinus rekent vanuit 0
Angle = 0 - 0; // Start Angle //Sinus rekent vanuit 0
//LED on to show we are running
digitalWrite(LED, HIGH);
Radius = (tft.width() / 2) - 2;
Call_DrawCircle(Radius);
Color = White;
Call_NESW(Radius, Angle, Color); //North East South West
//Print author info
tft.setCursor(0, tft.height() - 8);
tft.setTextColor(White);
tft.println("Designed and made by Leon Boullart");
} //setup
void loop() {
/*
Color = White;
Call_NESW(Radius, Angle, Color); //Nord East South West
Color = BackGroundColor;
Call_NESW(Radius, Angle, Color); //Nord East South West
Angle = Angle + 10;
*/
} //loop
void Call_ClearScreen() {
tft.fillScreen(BackGroundColor);
} //Call_ClearScreen
void Call_InitSerial() {
Serial.begin(115200);
Serial.println("Hello STM32! Wait for loop...");
} //Call_InitSerial
void Call_InitTFTscreen() {
//Init TFT Screen
tft.begin();
tft.setRotation(0); //Connector down
Call_ClearScreen();
Serial.println("Now in Call_InitTFTscreen");
} //Call_InitTFTscreen
void Call_InitAngleEncoder() {
Serial.println("Now in Call_InitAngleEncoder");
} //Call_InitAngleEncoder
void Call_InitPINmodes() {
Serial.println("Now in Call_InitPINmodes");
//Define pinModes
pinMode(LED, OUTPUT);
} //Call_DefinePINmodes
void ReadAngleEncoder() {
Serial.println("Now in ReadAngleEncoder");
int dtValue = digitalRead(AngleEncoder_DT);
if (dtValue == HIGH) {
Angle--;
}
if (dtValue == LOW) {
Angle++;
}
//Hoek correctie rondom 0 graden
if (Angle < 0) { Angle = 359; };
if (Angle >= 360) { Angle = 0; };
//Call_TekenCompas(Angle);
Call_NESW(Radius, Angle, White);
//BuzzerFlag = true;
} //ReadAngleEncoder
void Call_DrawCircle(int Radius) {
tft.drawRect(0, 0, tft.width(), tft.width(), White); // Vierkant
tft.drawCircle(CompassOriginX, CompassOriginY, Radius, OuterCircleColor); //BuitenCirkel
tft.drawCircle(CompassOriginX, CompassOriginY, Radius - CircelDistance, InnerCircleColor); //BinnenCirkel
} //Call_DrawCircle
void Call_NESW(int Radius, int Angle, int Color ) {
//Tijdelijk
tft.drawFastHLine(0,
CompassOriginY, tft.width(), Cyan);
tft.drawFastVLine (CompassOriginX,
0,
tft.width(), Cyan);
tft.drawLine( CompassOriginX, CompassOriginY,
0, 0, Yellow);
tft.drawLine( CompassOriginX, CompassOriginY,
CompassOriginX + (tft.width() / 2),
0, Yellow);
tft.drawLine( CompassOriginX, CompassOriginY,
CompassOriginX + (tft.width() / 2),
CompassOriginY + (tft.width() / 2), Yellow);
tft.drawLine( CompassOriginX, CompassOriginY,
0, CompassOriginX + (tft.width() / 2), Yellow);
Serial.println();
Serial.print("Angle = ");Serial.print(Angle);
tft.setTextColor(Color);
int DrawAngle = Angle;
//Print Noord
DrawAngle = DrawAngle + 0;
Serial.println();
Serial.print("Noord = ");Serial.print(DrawAngle);
SinVal = (sin(DrawAngle * (3.1415 / 180)));
CosVal = (cos(DrawAngle * (3.1415 / 180)));
X1 = CompassOriginX + ( CosVal * Radius * 0.85 ) - 2; // -2=midchar
Y1 = CompassOriginY - ( SinVal * Radius * 0.85 ) - 0; // -0=midchar
tft.setCursor( X1, Y1 );
tft.print("N");
//Print East
DrawAngle = DrawAngle + 270;
Serial.println();
Serial.print("Oost = ");Serial.print(DrawAngle);
SinVal = (sin(DrawAngle * (3.1415 / 180)));
CosVal = (cos(DrawAngle * (3.1415 / 180)));
X1 = CompassOriginX + ( CosVal * Radius * 0.85 ) - 4; // -4=midchar
Y1 = CompassOriginY - ( SinVal * Radius * 0.85 ) - 3; // -3=midchar
tft.setCursor( X1, Y1 );
tft.print("E");
//Print South
DrawAngle = DrawAngle - 90;
Serial.println();
Serial.print("South = ");Serial.print(DrawAngle);
SinVal = (sin(DrawAngle * (3.1415 / 180)));
CosVal = (cos(DrawAngle * (3.1415 / 180)));
X1 = CompassOriginX + ( CosVal * Radius * 0.85 ) - 1; // -1=midchar
Y1 = CompassOriginY - ( SinVal * Radius * 0.85 ) - 5; // -5=midchar
tft.setCursor( X1, Y1 );
tft.print("S");
//Print West
DrawAngle = DrawAngle - 90;
Serial.println();
Serial.print("West = ");Serial.print(DrawAngle);
SinVal = (sin(DrawAngle * (3.1415 / 180)));
CosVal = (cos(DrawAngle * (3.1415 / 180)));
X1 = CompassOriginX + ( CosVal * Radius * 0.85 ) + 1; // +1=midchar
Y1 = CompassOriginY - ( SinVal * Radius * 0.85 ) - 2; // -2=midchar
tft.setCursor( X1, Y1 );
tft.print("W");
Serial.println();
} //Call_NESW
/*
//Random printing
tft.setCursor(2,2);
tft.println("Leon Boullart");
tft.println();
tft.print("CompassOriginX = ");tft.print(CompassOriginX);
tft.println();
tft.print("CompassOriginY = ");tft.print(CompassOriginY);
*/