Bienvenido a los foros de FT81x Manía. Te invitamos a regístrate totalmente gratis. Disfruta de tu experiencia con un grandes amigos y Staff.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Thread Contributor: raufjayToggle test

#1
0
# include <EEPROM.h>
# include <SPI.h>
# include <GD2UB.h>

uint16_t togchk=1,toggle=0;
bool btenm;

void setup()

{
Serial.begin(115200);
GD.begin();

}
void loop()
{
GD.cmd_gradient(0, 40, 0x282830,0, 272, 0x606040);
GD.cmd_text(240, 100, 31, OPT_CENTER, "Toggle Test");
//uint16_t val, range;

 GD.Tag(10);                                 // Wifi ON/OFF toggle switch
       if(togchk)
       toggle=65535;
       GD.cmd_toggle(240,260,80,30,0,toggle,"OFF" "\xff" "ON  "); // Wifi ON/OFF
       GD.cmd_track(240,320,80,40,10);
       toggle=0;

GD.get_inputs();
 switch (GD.inputs.track_tag & 0xff)
 {
   case 10:
   togchk = GD.inputs.track_val *2L /65536;  //value = GD.inputs.track_val;
   if (togchk != 0)
   btenm = 1;
   else
   btenm =0;
   break;
 }
 
GD.swap();
Serial.print("tagchk=");Serial.println(tagchk);
Serial.print("btenm"); Serial.println(btenm);
}
Hello, I tried with Toggle switch.

I wanted to read toggle switch and if it is ON, a flag btenm will become one. And if the toggle switch turns off, the flag btenm become zero.

I tried to code it, and it works ok. Can you please check and let me know if there is any impvoement possible?
Reply
#2
1
Better response on post RE: Toggle testHello @ raufjay , please use this code to check if the toggle function works for you;

# include <EEPROM.h>
# include <SPI.h>
# include <GD2UB.h>

static uint16_t valu  = 0;
#define TAG_TOGGLE    202  

static uint16_t verano  = 0;
#define TAG_TOGGLE_1    203  

static uint16_t salva  = 0;
#define TAG_TOGGLE_2    204  

static uint16_t fade  = 0;
#define TAG_TOGGLE_3    205

static uint16_t desper  = 0;
#define TAG_TOGGLE_4    206  

void setup() {
GD.begin();
menu();
}

void loop() { }

void menu() {
 do {

  GD.get_inputs(); 
  GD.ClearColorRGB(0x000015);
  GD.Clear();
     
  GD.ColorRGB(0xffffff); 
  GD.Tag(1);
  GD.cmd_fgcolor(0xff0000);
  GD.cmd_button(20, 410, 100, 50, 30, OPT_FLAT, "Salir"); GD.Tag(255); 
    if (GD.inputs.tag==1) {delay(150); // yout function


// ------------------------------------------------------------
  GD.cmd_text(40,  80, 30, 0, "Horario Verano ?");
  GD.cmd_text(40, 130, 30, 0, "Salvapantalla ?"); 
  GD.cmd_text(40, 180, 30, 0, "Activar Fade ?");  
  GD.cmd_text(40, 230, 30, 0, "Despertador ?");   

  switch (GD.inputs.track_tag & 0xff) {
  case TAG_TOGGLE_1:
  verano = GD.inputs.track_val ;  // your function
  }

  GD.Tag(TAG_TOGGLE_1);
  GD.cmd_toggle(400, 95, 50, 29, 0, verano, "No" "\xff" "Yes");
  GD.cmd_track( 400, 95, 50, 29, TAG_TOGGLE_1);    

// -----------------------------------------------------------
  switch (GD.inputs.track_tag & 0xff) {
  case TAG_TOGGLE_2:
  salva = GD.inputs.track_val ;  // yout function
  }

  GD.Tag(TAG_TOGGLE_2);
  GD.cmd_toggle(400, 145, 50, 29, 0, salva, "No" "\xff" "Yes");
  GD.cmd_track( 400, 145, 50, 29, TAG_TOGGLE_2);    

// -----------------------------------------------------------
  switch (GD.inputs.track_tag & 0xff) {
  case TAG_TOGGLE_3:
  fade = GD.inputs.track_val ; // yout function
  }

  GD.Tag(TAG_TOGGLE_3);
  GD.cmd_toggle(400, 195, 50, 29, 0, fade, "No" "\xff" "Yes");
  GD.cmd_track( 400, 195, 50, 29, TAG_TOGGLE_3);    

// -----------------------------------------------------------
  switch (GD.inputs.track_tag & 0xff) {
  case TAG_TOGGLE_4:
  desper = GD.inputs.track_val ; // yout function
  }

  GD.Tag(TAG_TOGGLE_4);
  GD.cmd_toggle(400, 245, 50, 29, 0, desper, "No" "\xff" "Si");
  GD.cmd_track( 400, 245, 50, 29, TAG_TOGGLE_4);
      
     GD.swap(); 
  } while(1);
}
This code is a demo from friends @ TFTLCDCyg
Reply
#3
1
Better response on post RE: Toggle testDeclare GD.get_inputs (); first:

# include <GD2UD.h>

uint16_t togchk=1,toggle=0;
bool btenm;

void setup()
{
  GD.begin();
  MP();
}
void loop(){} //Nothing to do here!

void MP()
{
  while(1)
  {
    GD.get_inputs(); 
    GD.cmd_gradient(0, 40, 0x282830,0, 272, 0x606040);
    GD.cmd_text(240, 100, 31, OPT_CENTER, "Toggle Test");
    //uint16_t val, range;

    GD.Tag(10);                                 // Wifi ON/OFF toggle switch
       if(togchk)
       toggle=65535;
       GD.cmd_toggle(240,260,80,30,0,toggle,"OFF" "\xff" "ON  "); // Wifi ON/OFF
       GD.cmd_track(240,320,80,40,10);
       toggle=0;

    switch (GD.inputs.track_tag & 0xff) 
    {
      case 10:
        togchk = GD.inputs.track_val *2L /65536;  //value = GD.inputs.track_val;
        if (togchk != 0)
        btenm = 1;
      else
        btenm =0;
      break;
    }

    GD.cmd_text(500, 237, 30, 0, "togchk=");  GD.cmd_number(650, 237, 30, OPT_RIGHTX | OPT_SIGNED, togchk);
    GD.cmd_text(500, 267, 30, 0, "btenm=");  GD.cmd_number(650, 267, 30, OPT_RIGHTX | OPT_SIGNED, btenm);
    
    GD.swap();
    //Serial.print("togchk=");Serial.println(togchk);
    //Serial.print("btenm"); Serial.println(btenm);
  }
}
Let me see the code more carefully, be patient!
Reply
#4
1
Better response on post RE: Toggle testTry this with the suggestions of ligthcalamar


# include <GD2UD.h>

uint16_t togchk=0;
bool btenm=1;

static uint16_t WIFI;
#define TAG_TOGGLE_1     10

void setup()
{
  GD.begin();
  MP();
}
void loop(){}

void MP()
{
  while(1)
  {
    GD.get_inputs(); 
    GD.cmd_gradient(0, 40, 0x282830,0, 272, 0x606040);
    GD.cmd_text(240, 100, 31, OPT_CENTER, "Toggle Test");

    GD.cmd_text(40,  200, 30, 0, "WIFI");
    GD.Tag(TAG_TOGGLE_1);
    GD.cmd_toggle(250, 207, 60, 30, 0, WIFI, "On" "\xff" "Off");
    GD.cmd_track( 250, 207, 60, 30, TAG_TOGGLE_1);

     switch (GD.inputs.track_tag & 0xff) 
     {
      case TAG_TOGGLE_1:
      WIFI = GD.inputs.track_val ;  // your function
      togchk = GD.inputs.track_val *2L /65536;
     }
    if(togchk==0){btenm = 1;}else{btenm = 0;}
    GD.cmd_text(500, 237, 30, 0, "togchk=");  GD.cmd_number(650, 237, 30, OPT_RIGHTX | OPT_SIGNED, togchk);
    GD.cmd_text(500, 267, 30, 0, "btenm=");  GD.cmd_number(650, 267, 30, OPT_RIGHTX | OPT_SIGNED, btenm);
    
    GD.swap();    
  }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)