Post by jc07 on Nov 1, 2019 21:21:20 GMT -8
Hey Guys,
I am new to this community but I have done a lot of research to find the issue with my code. I have a New Haven Display (NHD-4.3-480272ft-csxn-ctp) with the arduino sheild (NHD-FT81x.shield) plugged into a arduino uno.
The issue that I have been having is that when I upload this code I can get it to display the screen I want if i comment out GD.get_inputs();
. I am needed to use the button inputs to make a arduino HMI for a project I am working on. Is there another way that I can approach to use multiple buttons on the screen and receiving feedback for button states.
If I leave GD.get_inputs();
uncommented them my screen remains black after i do my touch calibrating. Do i need to call to another function to fix the issue? Let me know what i can and do and what i am doing wrong. Do you by chance have some example code that I can base my change off of?
I am new to this community but I have done a lot of research to find the issue with my code. I have a New Haven Display (NHD-4.3-480272ft-csxn-ctp) with the arduino sheild (NHD-FT81x.shield) plugged into a arduino uno.
The issue that I have been having is that when I upload this code I can get it to display the screen I want if i comment out GD.get_inputs();
. I am needed to use the button inputs to make a arduino HMI for a project I am working on. Is there another way that I can approach to use multiple buttons on the screen and receiving feedback for button states.
If I leave GD.get_inputs();
uncommented them my screen remains black after i do my touch calibrating. Do i need to call to another function to fix the issue? Let me know what i can and do and what i am doing wrong. Do you by chance have some example code that I can base my change off of?
#include <EEPROM.h>
#include <SPI.h>
#include <GD2.h>
#define ADD 1
#define SUB 1
#define SurfButton 0
#define LaunchButton 1
#define SurfUp 2
#define SurfDn 3
#define LaunchUp 4
#define LaunchDn 5
#define Pressed 0
#define Released 255
long ReleasedColor = 0x171d3e;
long PressedColor = 0xa9a9a9;
int Surf = Released; int SurfColor = ReleasedColor;
int SurfPerUp = Released; int SurfPerUpColor = ReleasedColor;
int SurfPerDn = Released; int SurfPerDnColor = ReleasedColor;
int Launch = Released; int LaunchColor = ReleasedColor;
int LaunchPerUp = Released; int LaunchPerUpColor = ReleasedColor;
int LaunchPerDn = Released; int LaunchPerDnColor = ReleasedColor;
unsigned int Surf_Percentage = 65;
unsigned int Launch_Percentage = 85;
unsigned int Current_Position = 55;
#define Home 0
void Screen()
{
GD.Clear();
GD.cmd_gauge(240, 105, 130, OPT_NOBACK, 10, 5, Current_Position, 100);
GD.cmd_number(215, 140, 31, 0, Current_Position);
GD.cmd_text(265, 140, 28, 0, "%");
GD.cmd_text(385, 132, 28, 0, "Launch %");
GD.cmd_number(410, 1, 31, 0, Launch_Percentage);
GD.cmd_text(25, 132, 28, 0, "Surf %");
GD.cmd_number(20, 1, 31, 0, Surf_Percentage);
GD.Tag(SurfButton);
GD.cmd_fgcolor(SurfColor);
GD.cmd_button(100, 220, 120, 36, 28, Surf, "Surf");
GD.cmd_track(100, 220, 120, 36,SurfButton);
GD.Tag(LaunchButton);
GD.cmd_fgcolor(LaunchColor);
GD.cmd_button(270, 220, 120, 36, 28, Launch, "Launch");
GD.cmd_track(270, 220, 120, 36,LaunchButton);
GD.Tag(SurfUp);
GD.cmd_fgcolor(SurfPerUpColor);
GD.cmd_button(25, 52, 40, 60, 27, SurfPerUp, "UP");
GD.cmd_track(25, 52, 40, 60,SurfUp);
GD.Tag(SurfDn);
GD.cmd_fgcolor(SurfPerDnColor);
GD.cmd_button(25, 180, 40, 60, 27, SurfPerDn, "DN");
GD.cmd_track(25, 180, 40, 60,SurfDn);
GD.Tag(LaunchUp);
GD.cmd_fgcolor(LaunchPerUpColor);
GD.cmd_button(415, 50, 40, 60, 27, LaunchPerUp, "UP");
GD.cmd_track(415, 50, 40, 60,LaunchUp);
GD.Tag(LaunchDn);
GD.cmd_fgcolor(LaunchPerDnColor);
GD.cmd_button(415, 180, 40, 60, 27, LaunchPerDn, "DN");
GD.cmd_track(415, 180, 40, 60,LaunchDn);
GD.Tag(6);
GD.swap();
}
void TouchScreen()
{
GD.get_inputs();
switch(GD.inputs.tag)
{
case SurfButton:
break;
case LaunchButton:
break;
case SurfUp:
//Surf_Percentage = Surf_Percentage + ADD;
break;
case SurfDn:
//Surf_Percentage = Surf_Percentage - SUB;
break;
case LaunchUp:
//Launch_Percentage = Launch_Percentage + ADD;
break;
case LaunchDn:
//Launch_Percentage = Launch_Percentage - SUB;
break;
}
}
void setup()
{
Serial.begin(9600); // JCB
GD.begin(GD_CALIBRATE);
GD.ClearColorRGB(64,64,64);
GD.Clear();
GD.cmd_text(240, 100, 30, OPT_CENTERX, "please tap on the dot");
GD.cmd_calibrate();
}
void loop()
{
Screen();
TouchScreen();
}
#include <SPI.h>
#include <GD2.h>
#define ADD 1
#define SUB 1
#define SurfButton 0
#define LaunchButton 1
#define SurfUp 2
#define SurfDn 3
#define LaunchUp 4
#define LaunchDn 5
#define Pressed 0
#define Released 255
long ReleasedColor = 0x171d3e;
long PressedColor = 0xa9a9a9;
int Surf = Released; int SurfColor = ReleasedColor;
int SurfPerUp = Released; int SurfPerUpColor = ReleasedColor;
int SurfPerDn = Released; int SurfPerDnColor = ReleasedColor;
int Launch = Released; int LaunchColor = ReleasedColor;
int LaunchPerUp = Released; int LaunchPerUpColor = ReleasedColor;
int LaunchPerDn = Released; int LaunchPerDnColor = ReleasedColor;
unsigned int Surf_Percentage = 65;
unsigned int Launch_Percentage = 85;
unsigned int Current_Position = 55;
#define Home 0
void Screen()
{
GD.Clear();
GD.cmd_gauge(240, 105, 130, OPT_NOBACK, 10, 5, Current_Position, 100);
GD.cmd_number(215, 140, 31, 0, Current_Position);
GD.cmd_text(265, 140, 28, 0, "%");
GD.cmd_text(385, 132, 28, 0, "Launch %");
GD.cmd_number(410, 1, 31, 0, Launch_Percentage);
GD.cmd_text(25, 132, 28, 0, "Surf %");
GD.cmd_number(20, 1, 31, 0, Surf_Percentage);
GD.Tag(SurfButton);
GD.cmd_fgcolor(SurfColor);
GD.cmd_button(100, 220, 120, 36, 28, Surf, "Surf");
GD.cmd_track(100, 220, 120, 36,SurfButton);
GD.Tag(LaunchButton);
GD.cmd_fgcolor(LaunchColor);
GD.cmd_button(270, 220, 120, 36, 28, Launch, "Launch");
GD.cmd_track(270, 220, 120, 36,LaunchButton);
GD.Tag(SurfUp);
GD.cmd_fgcolor(SurfPerUpColor);
GD.cmd_button(25, 52, 40, 60, 27, SurfPerUp, "UP");
GD.cmd_track(25, 52, 40, 60,SurfUp);
GD.Tag(SurfDn);
GD.cmd_fgcolor(SurfPerDnColor);
GD.cmd_button(25, 180, 40, 60, 27, SurfPerDn, "DN");
GD.cmd_track(25, 180, 40, 60,SurfDn);
GD.Tag(LaunchUp);
GD.cmd_fgcolor(LaunchPerUpColor);
GD.cmd_button(415, 50, 40, 60, 27, LaunchPerUp, "UP");
GD.cmd_track(415, 50, 40, 60,LaunchUp);
GD.Tag(LaunchDn);
GD.cmd_fgcolor(LaunchPerDnColor);
GD.cmd_button(415, 180, 40, 60, 27, LaunchPerDn, "DN");
GD.cmd_track(415, 180, 40, 60,LaunchDn);
GD.Tag(6);
GD.swap();
}
void TouchScreen()
{
GD.get_inputs();
switch(GD.inputs.tag)
{
case SurfButton:
break;
case LaunchButton:
break;
case SurfUp:
//Surf_Percentage = Surf_Percentage + ADD;
break;
case SurfDn:
//Surf_Percentage = Surf_Percentage - SUB;
break;
case LaunchUp:
//Launch_Percentage = Launch_Percentage + ADD;
break;
case LaunchDn:
//Launch_Percentage = Launch_Percentage - SUB;
break;
}
}
void setup()
{
Serial.begin(9600); // JCB
GD.begin(GD_CALIBRATE);
GD.ClearColorRGB(64,64,64);
GD.Clear();
GD.cmd_text(240, 100, 30, OPT_CENTERX, "please tap on the dot");
GD.cmd_calibrate();
}
void loop()
{
Screen();
TouchScreen();
}