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: raufjayReading slider position values

#1
0
Hello,

I want to control the screen brightness with the help of using a slider. So user can control the screen brightness.

I am using the following code:

uint16_t brtvalue;

GD.Tag(31);                               // Brightness slider tag number
        GD.cmd_text(150,120,18,0,"Brightness");
        GD.cmd_slider(150,100,180,8,0,50,100)  ;  // brightness, default value 50.
        GD.cmd_track(150,100,180,8,30);

I dont know how to read the current brightness value in the brtvalue integer.

Can you help me on this?

Thanks,

Rauf

Hello again,
Please also help me in reading Toggle switch values.
Thanks,
Rauf
Reply
#2
1
Better response on post RE: Reading slider position valuesHello @ raufjay

This is an example code to control the brightness of your screen;

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


#define TAG_SLIDER    201
byte brightness = 90;       // 90 brightness PWM Backlight


void brillo() {        // function brightness
   
  do {    
  GD.ClearColorRGB(0x000015);
  GD.Clear(); 

  GD.SaveContext();
  lineas();
  GD.RestoreContext(); 

  GD.ColorRGB(0xffff00);
  blockText1(185, 150, 31,  "Control screen FT81x");

  GD.Tag(1);
  GD.cmd_fgcolor(0x000000); 
  GD.ColorRGB(0xffffff);
  GD.cmd_romfont(1, 32);
  GD.cmd_button(20, 20, 760, 70, 1, 0, "Control brightness FT81x"); GD.Tag(255);
     if (GD.inputs.tag==1) {
       delay(175);  }
         
  GD.SaveContext(); 
  GD.Tag(TAG_SLIDER);
  GD.cmd_fgcolor(0xffff00);                     
  GD.ColorRGB(0x0000ff); 
  GD.cmd_bgcolor(0x000000);      
  GD.cmd_slider(150, 270, 450, 15, 0, brightness, 128);
  GD.cmd_track( 150, 270, 450, 15, TAG_SLIDER);

  GD.get_inputs();
  switch (GD.inputs.track_tag & 0xff) {
  case TAG_SLIDER:
  brightness = GD.inputs.track_val * 128L / 65535;
  GD.wr(REG_PWM_DUTY,(brightness));
  break;
  }
  
  GD.RestoreContext();

  GD.SaveContext(); 
  GD.ColorRGB(0xffffff);   
  GD.cmd_romfont(1, 34);
  GD.cmd_number(GD.w /2 - 50, 370, 1, 0, brightness); 
  GD.RestoreContext();

  GD.swap();
 } while(1);



void lineas() {
  
  GD.Begin(LINES);
  GD.SaveContext();
  GD.Vertex2ii(0, 0, 20, 0);         // LINEA SUPERIOR DE LA PANTALLA
  GD.Vertex2ii(319, 0, 20, 0);
  GD.VertexTranslateX(16*320); GD.Vertex2ii(480, 0, 20, 0);
  GD.VertexTranslateX(16*320); GD.Vertex2ii(0, 0, 20, 0);
  GD.RestoreContext();

  GD.SaveContext();
  GD.Vertex2ii(0, 478, 20, 0);        // LINEA INFERIOR DE LA PANTALLA
  GD.Vertex2ii(478, 478, 20, 0);
  GD.VertexTranslateX(16*480); GD.Vertex2ii(0, 478, 20, 0);
  GD.VertexTranslateX(16*320); GD.Vertex2ii(478, 478, 20, 0);     
  GD.RestoreContext();
  
  GD.SaveContext();
  GD.Vertex2ii(0, 480, 20, 0);        // LINEA LATERAL IZQUIERDA
  GD.Vertex2ii(0, 0, 20, 0);
  GD.RestoreContext(); 
                                      // LINEA LATERAL DERECHA
  GD.SaveContext();
  GD.VertexTranslateX(16 * 318); GD.Vertex2ii(480, 0, 20, 0);     
  GD.VertexTranslateX( 8 * 636);  GD.Vertex2ii(480, 480, 20, 0);                    
  GD.RestoreContext();           
  GD.End(); 
}

void setup() {

 GD.begin();
 brillo();
}

void loop() { }
Reply
#3
1
Better response on post RE: Reading slider position valuesHello,

Thank you very much for the great help.

I tried this and it worked fantastic.

I just had to add the following function in the code.
static void blockText1(int x, int y, byte font, const char *s)
{
GD.SaveContext();
GD.ColorRGB(0x000000);
GD.cmd_text(x-1, y-1, font, 0, s);
GD.cmd_text(x+1, y-1, font, 0, s);
GD.cmd_text(x-1, y+1, font, 0, s);
GD.cmd_text(x+1, y+1, font, 0, s);
GD.RestoreContext();
GD.cmd_text(x, y, font, 0, s);
}
I mentioned it above, in case if any folk would like to try this code out.

Thank you,

Rauf
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)