Go Down

Topic: Picaso-Serial-Arduino-Library-master (Read 900 times) previous topic - next topic

Jesiah

Hi, I am very new to programming and could use a little help fixing up my code please.  I am using a MEGA 2560 and a uLCD43pt from 4D.  I am trying to make a 2 button GUI which will either flash 3 LEDs or have the LEDs light up in sequence.  I am also trying just to print a little text on the screen.  I've tried to decipher the bigdemo sketch but it's above my skill level and is too much information all at once.  The big demo sketch came with the library and I tried to post but its too big to post.  You can find a copy of the sketch here:   https://github.com/4dsystems/Picaso-Serial-Arduino-Library/tree/master/Arduino

Thanks for the help,
Jes

2 Button GUI

Code: [Select]

int even =0;
const int Blue1 = 22 ; // Blue LED Array Pin numbers
const int Blue2 = 24;
const int Blue3 = 26;

#define DisplaySerial Serial;
#include <SoftwareSerial.h>;
SoftwareSerial DisplaySerial(2,3);

#include "Picaso_Serial_4DLib.h"
#include "bigdemo.h"
#include "Picaso_const4D.h"
Picaso_Serial_4DLib Display(&DisplaySerial);

void setup()
{

 
 pinMode(Blue1,OUTPUT);  // Initialize Blue pins as outputs
 pinMode(Blue2,OUTPUT);
 pinMode(Blue3,OUTPUT);
 
}

void flash()
{
for (int i=0; i<5;i++)
 {
   digitalWrite(Blue1,LOW);
   digitalWrite(Blue2,LOW);
   digitalWrite(Blue3,LOW);
 
   delay(1000);
 
   digitalWrite(Blue1,HIGH);
   digitalWrite(Blue2,HIGH);
   digitalWrite(Blue3,HIGH);
 
   delay(1000);
 }
 
}

void sequence()
{
  for (int i=1; i<4;i++)
  {
    even = 20+(i*2);
    digitalWrite(even,HIGH);
    delay(1000);
    digitalWrite(even,LOW);
  }
 
 Display.gfx_Cls();
 Display.txt_BGcolour(BLACK);
 Display.txt_FGcolour(YELLOW);
 Display.putstr("The LED's flashed %d times", i);
 delay(3000);

}

void loop ()
{
 DisplaySerial.begin(9600) ;
 Display.TimeLimit4D   = 5000 ; // 5 second timeout on all commands
 Display.gfx_Cls() ;
 Display.txt_BGcolour(BLACK);
 Display.txt_FGcolour(YELLOW);
 Display.txt_MoveCursor(6, 2) ;
 Display.txt_Height(2) ;
 Display.txt_Width(2) ;
 Display.putstr("Main Menu");
 
 Display.gfx_BevelShadow(1) ;                // make it really dark
 Display.gfx_BevelWidth(6) ;
 Display.gfx_Button(flash, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "LED Flash") ;
 delay(100) ;
 Display.gfx_Button(sequence, 120,50, YELLOW, PURPLE, FONT3, 1, 1, "LED Sequence") ;
 delay(100) ;
 
}




Docedison

All of the code end of this stuff was above my head completely.. A year ago. What I suggest you do is some simpler little task's on the GLCD first to begin to learn.
You haven't posted enough information... there is at the lower left corner of the message box a label called "Additional Options..." click on it and upload the files necessary to compile the complete program. You need to post the sketch and the compiler messages and a schematic if required. I own 2 of the 3.2 " display's and think highly of them. I use Revilo's (ave33) library perhaps it might be easier for you. It's available searcl for revilo and 4D Systems.

Bob
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Jesiah

Hi, I've made progress thanks to Francois posting a hello world program which simplified the big demo program because I can cut and paste and play.  I have 2 questions though, first one is in regards to just displaying simple text on the screen.  If I place the integer 4 in the variable i for example, how can I call up that 4 and have it posted?  I tried the following which failed:

Display.putstr("The LED's flashed %d times", i);
Display.putstr(i);
Display.txt(i);

My second question is in regards to creating buttons.  I've been able to create a 2 button GUI on the screen but I am not sure how to distinguish between the 2 touch regions.  I also want to be able to call up either the sequence function or the flash function depending on whether the red or blue button has been touched.  Here is the code I have so far,  I haven't included the sequence or flash function to make it easier to read.
There are no errors yet. 
Code: [Select]

#include <Picaso_Serial_4DLib.h>               
#include <Picaso_Const4D.h>
#define DisplaySerial Serial
Picaso_Serial_4DLib Display(&DisplaySerial);

void setup(void){
 
 
 
 
  pinMode(2, OUTPUT);
  DisplaySerial.begin(9600) ;
  Display.TimeLimit4D = 5000 ;
 
  digitalWrite(2, HIGH);
  delay(100);
  digitalWrite(2, LOW);
 
  delay(3000);
 
  // Title
  Display.gfx_Cls() ;
  Display.txt_Attributes(ITALIC + UNDERLINED) ;
  Display.txt_Height(4) ;
  Display.txt_Width(4) ;
  Display.txt_MoveCursor(1.5, 3) ;
  Display.putstr("TOP MENU\n") ;
 
  // Buttons
 
  Display.txt_MoveCursor(3, 2) ;
  Display.txt_Height(1) ;
  Display.txt_Width(1) ;
  Display.txt_FGcolour(YELLOW);
  Display.putstr("Sequence                   Flash") ;

  Display.touch_Set(TOUCH_ENABLE) ;
  Display.touch_DetectRegion(70,175, 120, 225) ;
  Display.gfx_RectangleFilled(70,175, 120, 225, BLUE) ;
 
  Display.touch_Set(TOUCH_REGIONDEFAULT) ;
  Display.touch_DetectRegion(300,175, 350, 225) ;
  Display.gfx_RectangleFilled(300,175, 350, 225, RED) ;
  Display.touch_Set(TOUCH_REGIONDEFAULT) ;
do {} while (Display.touch_Get(TOUCH_STATUS) != TOUCH_PRESSED);


}

void loop()
{
}

Go Up