0% found this document useful (0 votes)
19 views7 pages

New Text Documenterwe

werweeeee

Uploaded by

Ahmed Rezk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views7 pages

New Text Documenterwe

werweeeee

Uploaded by

Ahmed Rezk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

#include <Adafruit_GFX.

h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
int button = 10;
#define POTENTIOMETER_PIN A5
#include <EEPROM.h>
int value1 ;
int value2 ;
int value3 ;
float value4 ;
float value5 ;
float stepr ;
float stepl ;
int boot ;

// ALL Touch panels and wiring is DIFFERENT


const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341

const int TS_LEFT = 910, TS_RT = 169, TS_TOP = 900, TS_BOT = 180;

int n_new = 0 ;
int n_old = 0 ;

int pixel_x, pixel_y; //Touch_getXY() updates global vars


bool Touch_getXY(void)
{
pinMode(YP, OUTPUT); //restore shared pins
pinMode(XM, OUTPUT);
digitalWrite(YP, HIGH); //because TFT control pins
digitalWrite(XM, HIGH);

#define BLACK 0x0000


#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
float i=0;
int randomvalue=-90;
int returnx=0;
float angle,x,y;
bool down;
unsigned long old =0;
unsigned long current =0;
long interval=0;

void setup(void)
{
Serial.begin(9600);
uint16_t ID = tft.readID();
Serial.print("TFT ID = 0x");
Serial.println(ID, HEX);
if (ID == 0xD3D3) ID = 0x9486; // write-only shield
pinMode(button, INPUT);
digitalWrite(button, HIGH); //activate arduino internal pull up
tft.begin(ID);
tft.setRotation(1); //PORTRAIT
tft.setTextSize(3);
tft.fillScreen(BLACK);

if (digitalRead(button)==LOW){
tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.setCursor(103,45);
tft.print("ELBAHLWAN DIGITAL RUDER");
tft.setTextColor(WHITE, RED);
tft.setCursor(170,75);
tft.print("Device Setup");

tft.drawCircle(100,240,65,WHITE);
tft.drawCircle(240,240,65,WHITE);
tft.drawCircle(380,240,65,WHITE);
////
tft.setTextSize(7);
tft.setTextColor(GREEN, BLACK);
tft.setCursor(340,215);
tft.print(">>");

for (int x=1; x<=20; x=x+1)


{
tft.setTextSize(3);
tft.setTextColor(WHITE, BLACK);
tft.setCursor(375,140);
tft.print(x);
delay(1000);
tft.setTextColor(BLACK, BLACK);
tft.setCursor(375,140);
tft.print(x);
Serial.println(analogRead(POTENTIOMETER_PIN));

}
int val = analogRead(POTENTIOMETER_PIN) ;
EEPROM.put(0, (val/5));
delay(1000);
tft.setTextColor(GREEN, BLACK);
tft.setCursor(365,140);
tft.print("OK");
////
tft.setTextSize(7);
tft.setTextColor(GREEN, BLACK);
tft.setCursor(225,215);
tft.print("0");

for (int x=1; x<=20; x=x+1)


{
tft.setTextSize(3);
tft.setTextColor(WHITE, BLACK);
tft.setCursor(235,140);
tft.print(x);
delay(1000);
tft.setTextColor(BLACK, BLACK);
tft.setCursor(235,140);
tft.print(x);
Serial.println(analogRead(POTENTIOMETER_PIN));

}
val = analogRead(POTENTIOMETER_PIN) ;
EEPROM.put(1, (val/5));
delay(1000);
tft.setTextColor(GREEN, BLACK);
tft.setCursor(227,140);
tft.print("OK");

////
tft.setTextSize(7);
tft.setTextColor(GREEN, BLACK);
tft.setCursor(60,215);
tft.print("<<");
for (int x=1; x<=20; x=x+1)
{
tft.setTextSize(3);
tft.setTextColor(WHITE, BLACK);
tft.setCursor(95,140);
tft.print(x);
delay(1000);
tft.setTextColor(BLACK, BLACK);
tft.setCursor(95,140);
tft.print(x);
Serial.println(analogRead(POTENTIOMETER_PIN));

}
val = analogRead(POTENTIOMETER_PIN) ;
EEPROM.put(2, (val/5));
delay(1000);
tft.setTextColor(GREEN, BLACK);
tft.setCursor(90,140);
tft.print("OK");

tft.fillScreen(BLACK);

tft.setTextColor(WHITE, BLACK);
tft.setCursor(240, 240);
tft.drawCircle(240,240,223,WHITE);

for (i=-120; i<=-30; i=i+0.4)


{
float angle = (i / 57.2958) - 1.57;
float x= 240 + cos(angle) * 220;
float y = 239+sin(angle) * 220;
tft.drawLine(240, 239,x,y, RED);
}
for (i=-30; i<=30; i=i+0.4)
{
float angle = (i / 57.2958) - 1.57;
float x= 240 + cos(angle) * 220;
float y = 239+sin(angle) * 220;
tft.drawLine(240, 239,x,y, WHITE);

}
for (i=30; i<=120; i=i+0.4)
{
float angle = (i / 57.2958) - 1.57;
float x= 240 + cos(angle) * 220;
float y = 239+sin(angle) * 220;
tft.drawLine(240, 239,x,y, GREEN);

tft.fillCircle(240,239,195,BLACK);
tft.drawCircle(240,239,194,WHITE);

i=randomvalue;
for (i=-90; i<=90; i=i+2)
{
float angle = (i / 57.2958) - 1.57;
float x= 240 + cos(angle) * 194;
float y = 239+sin(angle) * 194;
tft.drawLine(240, 239,x,y, WHITE);
}

tft.fillCircle(240,239,190,BLACK);

i=randomvalue;
for (i=-90; i<=90; i=i+10)
{
float angle = (i / 57.2958) - 1.57;
float x= 240 + cos(angle) * 194;
float y = 239+sin(angle) * 194;
tft.drawLine(240, 239,x,y, WHITE);
}

tft.fillCircle(240,239,185,BLACK);

tft.setTextSize(2);
tft.setTextColor(GREEN, BLACK);
tft.setCursor(235,60);
tft.print("0");

tft.setCursor(290,68);
tft.print("10");

tft.setCursor(345,100);
tft.print("20");

tft.setCursor(378,142);
tft.print("30");
tft.setCursor(398,200);
tft.print("40");

tft.setCursor(165,68);
tft.print("10");

tft.setCursor(114,100);
tft.print("20");

tft.setCursor(81,142);
tft.print("30");

tft.setCursor(61,200);
tft.print("40");

angle = (0 / 57.2958) - 1.57;


x= 240 + cos(angle) * 145;
y = 239+sin(angle) * 145;
float angle1 =angle - 1.57;
float angle2 =angle + 1.57;
float angle3 =angle + 3.14;
x= 240 + cos(angle) * 145;
y = 239+sin(angle) * 145;
float x1= 240 + cos(angle1) * 5;
float y1 = 239+sin(angle1) * 5;
float x2= 240 + cos(angle2) *5;
float y2 = 239+sin(angle2) * 5;
float x3= 240 + cos(angle3) *5;
float y3 = 239+sin(angle3) * 5;
tft.fillCircle(240,239,81,BLACK);
tft.fillTriangle(x,y,x1,y1,x2,y2, WHITE);
tft.fillTriangle(x1,y1,x2,y2,x3,y3, WHITE);

tft.setTextSize(2);
tft.setTextColor(WHITE, BLACK);
tft.setCursor(103,280);
tft.print("ELBAHLWAN DIGITAL RUDER");

tft.setTextSize(2);
tft.setTextColor(WHITE, RED);
tft.setCursor(10,10);
tft.print("MUSTAFA");

value1 = 415;
value2 = 670;
value3 = 790;

value4 = value2 - value1 ;


value5 = value3 - value2 ;

void loop(void)
{
boot = analogRead(POTENTIOMETER_PIN) ;
Serial.println(boot);

if( boot < value2)


{
stepr = value4 /90 ;
n_new =90-( (boot-value1) / stepr ) ;
}

if (boot > value2)


{
stepl = value5 /90 ;
n_new =((boot- value2) / stepl )*-1 ;

if(n_new>90)
{
n_new=90;
}
if(n_new<-90)
{
n_new=-90;
}
Serial.println(n_new);

if(abs(n_new-n_old )> 2 )
{
if(abs(n_new-n_old )< 45)
{

angle = (n_old / 57.2958) - 1.57;


x= 240 + cos(angle) * 155;
y = 239+sin(angle) * 155;
float angle1 =angle - 1.57;
float angle2 =angle + 1.57;
float angle3 =angle + 3.14;
x= 240 + cos(angle) * 155;
y = 239+sin(angle) * 155;
float x1= 240 + cos(angle1) * 20;
float y1 = 239+sin(angle1) * 20;
float x2= 240 + cos(angle2) *20;
float y2 = 239+sin(angle2) * 20;
float x3= 240 + cos(angle3) *20;
float y3 = 239+sin(angle3) * 20;
tft.fillTriangle(x,y,x1,y1,x2,y2, BLACK);
tft.fillTriangle(x1,y1,x2,y2,x3,y3, BLACK);

angle = (n_new / 57.2958) - 1.57;


x= 240 + cos(angle) * 155;
y = 239+sin(angle) * 155;
x= 240 + cos(angle) * 155;
y = 239+sin(angle) * 155;
float x11= 240 + cos(angle1) * 15;
float y11 = 239+sin(angle1) * 15;
float x22= 240 + cos(angle2) *15;
float y22 = 239+sin(angle2) * 15;
float x33= 240 + cos(angle3) *15;
float y33= 239+sin(angle3) * 15;
tft.fillTriangle(x,y,x11,y11,x22,y22, WHITE);
tft.fillTriangle(x11,y11,x22,y22,x33,y33, WHITE);
n_old = n_new ;
}

}
delay(500);

You might also like