Mapped 360 points representing a 360 degree turn of a pan on a Quickset pan/tilt motor. The 5K ohm feedback pot located on the pan motor is connected to 5 volts and run through a simple noise filter connected before the pan potentiometer input on A0. A 7 inch TFT CTE70 and mega 2560 are using the UTFT library. I need to draw a dot or small filled circle to represent the pan motion position. The small filled circle will move on top of a larger static circle which is labeled north, south east and west. Have developed a sketch but can't test it for couple of days. Even if it works it will be extremly slow since each x,y position of the solid circle is defined by 360 "if" statements. Please help with code that works and is faster. Some of the code was taken from the UTFT demo and buttons demo....
UTFT graphics and touch libraries at Electronics - Henning Karlsen. The full code sketch is attached and a sample of the code below was shortened to fit within the 9000 forum character limit.
CODE:
/* NEXT STEPS
- Connect D9,D10,D11 to scope and confirm ok (D8 already connected)
2.Change momentary button operation so touch button continously activated pan and tilt motors when held down. ( Press and hold pan and tilt touch buttons).
Make 360 if statements to define each x,y point to draw small dot or circle indicating pan position. Done.
*/
#include <UTFT.h>
#include <UTouch.h>
#include <UTFT_Buttons.h>
extern uint8_t SevenSegNumFont[];
extern uint8_t BigFont[]; //Declare font extern uint8_t BigFont[];
extern uint8_t SmallFont[];
UTFT myGLCD(CTE70CPLD,38,39,40,41); // Setup CTE70 TFT LCD/SD Shield for Arduino Mega
UTouch myTouch(6,5,4,3,2);
UTFT_Buttons myButtons(&myGLCD, &myTouch); // Setup UTFT buttons
int panPot = 0; //Declare and set pantPot to 0
int tiltPot = 0; //Declare and set tiltPot to 0
int panLeft = 0;
int panRight = 0;
int tiltUp = 0;
int tiltDown = 0;
int panLeftscope = 8;
int panRightscope = 9;
int tiltUpscope = 10;
int tiltDownscope = 11;
void setup()
{
// Serial.begin(9600);
pinMode(panLeftscope,OUTPUT);
pinMode(panRightscope,OUTPUT);
pinMode(tiltUpscope,OUTPUT);
pinMode(tiltDownscope,OUTPUT);
// Setup the LCD
myGLCD.InitLCD();
myGLCD.setFont(BigFont);
myGLCD.clrScr();
// Setup Touch and Buttons
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
myButtons.setTextFont(BigFont);
// pinMode(ledPin, OUTPUT);
//Draw "Remote 1" at top center of screen
myGLCD.setBackColor(255, 0, 0);
myGLCD.setFont(BigFont);
myGLCD.print("* REMOTE 1 *", CENTER, 1);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("N",150,110);
myGLCD.print("E",30,230);
myGLCD.print("S",150,350);
myGLCD.print("W",275,230);
myGLCD.print("UP",585,30);
myGLCD.print("DOWN",570,440);
//Draw Tilt vertical line
myGLCD.setColor(100, 150, 85);
myGLCD.setBackColor(0, 0, 0);
myGLCD.drawLine(600, 90, 600, 400);
//Draw Tilt line horizontal increments
for (int i=100; i<400; i+=10)
myGLCD.drawLine(595, i, 605, i);
}
void loop()
{
//Setup Pan Button
int pressed_button;
int panLeft = myButtons.addButton(340,80,150,30,"Pan Left");
int panRight = myButtons.addButton(340,180,150,30,"Pan Right");
int tiltUp = myButtons.addButton(340,280,150,30,"Tilt Up");
int tiltDown = myButtons.addButton(340,380,150,30,"Tilt Down");
myButtons.drawButton(panLeft);
myButtons.drawButton(panRight);
myButtons.drawButton(tiltUp);
myButtons.drawButton(tiltDown);
while(1)
{
if (myTouch.dataAvailable() == true)
{
pressed_button = myButtons.checkButtons();
if (pressed_button == panLeft)
{
digitalWrite(panLeftscope, HIGH);
delay(100);
digitalWrite(panLeftscope, LOW);
delay(100);
}
if (pressed_button == panRight)
{
digitalWrite(panRightscope, HIGH);
delay(100);
digitalWrite(panRightscope, LOW);
delay(100);
}
if (pressed_button == tiltUp)
{
digitalWrite(tiltUpscope, HIGH);
delay(100);
digitalWrite(tiltUpscope, LOW);
delay(100);
}
if (pressed_button == tiltDown)
{
digitalWrite(tiltDownscope, HIGH);
delay(100);
digitalWrite(tiltDownscope, LOW);
delay(100);
}
}
// else
{
// digitalWrite(panLeftscope, LOW);
}
// Setup Pan Number Indicator
int panPot = analogRead(A0);
panPot = map(panPot,0,1023,100,360);
myGLCD.setColor(255, 150, 100);
myGLCD.setBackColor(0,0,0);
myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(panPot,110,220,3);
//Setup Tilt Number Indicator
int tiltPot = analogRead(A1);
tiltPot = map(tiltPot,0,1023,100,200);
myGLCD.setColor(255, 150, 100);
myGLCD.setBackColor(0,0,0);
myGLCD.setFont(SevenSegNumFont);
myGLCD.printNumI(tiltPot,630,220,3);
// Draw Pan Circle
myGLCD.setColor(255,255,255);
int x=160;
int y=240;
int r=100;
myGLCD.drawCircle(x, y, r);
// if (panPot=1)
// {
// x=1,y=1
// }
// Serial.println(panLeft);
}
//"If" statements from mapped panPot analog read values from 1 to 359 to make filled circle
//that will follow large pan circle.
// Think x,y will not be ok. Will need to adjust values to follow circle
myGLCD.setColor(255,0,0);
if (panPot=1)
{
myGLCD.fillCircle(260,242,10);
}
if (panPot=2)
{
myGLCD.fillCircle(260,243,10);
}
if (panPot=3)
{
myGLCD.fillCircle(260,245,10);
}
if (panPot=4)
{
myGLCD.fillCircle(260,247,10);
}
if (panPot=5)
{
myGLCD.fillCircle(260,249,10);
}
if (panPot=6)
{
myGLCD.fillCircle(259,250,10);
}
if (panPot=7)
{
myGLCD.fillCircle(259,250,10);
}
if (panPot=8)
{
myGLCD.fillCircle(259,254,10);
}
if (panPot=9)
{
myGLCD.fillCircle(259,256,10);
}
if (panPot=10)
{
myGLCD.fillCircle(258,257,10);
}
if (panPot=11)
{
myGLCD.fillCircle(258,259,10);
}
if (panPot=12)
{
myGLCD.fillCircle(258,261,10);
}
if (panPot=13)
{
myGLCD.fillCircle(257,262,10);
}
if (panPot=14)
{
myGLCD.fillCircle(257,264,10);
}
if (panPot=15)
{
myGLCD.fillCircle(257,266,10);
}
if (panPot=16)
{
myGLCD.fillCircle(258,268,10);
}
if (panPot=17)
{
myGLCD.fillCircle(256,269,10);
}
if (panPot=18)
{
myGLCD.fillCircle(255,271,10);
}
if (panPot=19)
{
myGLCD.fillCircle(255,273,10);
}
if (panPot=20)
{
myGLCD.fillCircle(254,274,10);
}
if (panPot=21)
{
myGLCD.fillCircle(253,276,10);
}
if (panPot=22)
{
myGLCD.fillCircle(253,277,10);
}
if (panPot=23)
{
myGLCD.fillCircle(252,279,10);
}
if (panPot=24)
{
myGLCD.fillCircle(251,281,10);
}
if (panPot=25)
{
myGLCD.fillCircle(251,282,10);
}
if (panPot=26)
{
myGLCD.fillCircle(250,284,10);
}
if (panPot=27)
{
myGLCD.fillCircle(249,285,10);
}
if (panPot=28)
{
myGLCD.fillCircle(248,287,10);
}
if (panPot=29)
{
myGLCD.fillCircle(247,288,10);
}
if (panPot=30)
{
myGLCD.fillCircle(247,290,10);
}
if (panPot=31)
{
myGLCD.fillCircle(246,292,10);
}
}
WSFA_TFT_PanTilt_16.ino (28.3 KB)