Start a new topic

Changing button picture

 I want to change brightness of LED with one button in three stages. First press will Turn on LED on 100%, second on 50% and third on 10%. I already made five buttons (off, pressed, 100%, 50% and 10%) and I want to change picture of the button according to set brightness. So is there any option to change it? I know it's possible to change picture when used as component picture but I don't know how to change it  for buttons.


I also think itead should give more publication about components!


Raphaël


Thank you I works perfect


2 people like this

Thanks @Raphael. 


Every components has its main attribute that will refresh automatically without the command "ref".


which ones? THE BOLD ONES! see below:

For example: "txt" attribute is the main attribute of text component. If you want to change the "pic" and "txt" both attributes of t1 at the same time,you don't need to use "ref t1",but if you want to change the "pic" or other attributes of t1, except “txt”(the main attribute), you need to use "ref t1". 


It is the same to other components,and we have updated the wiki in"Nextion_Editor_Quick_Start_Guide".



1 person likes this

@ITEAD

In an earlier thread ( http://support.iteadstudio.com/support/discussions/topics/1000058422 ) you wrote that you would give more information about which parameters/attributes need the "ref" command. Where can we find this information?


Is there a list of which attributes that need to be refreshed with the "ref" command?

This is the code I use the button pics are pic 14 and pic2 13


Please can some one help me?

ino
(1001 Bytes)
cpp
(2.41 KB)
h
(1.27 KB)

Can you attach your HMI file?

hmi

HMI
(592 KB)

The led connected on pin 10 is working only the pictures don't work id button =b0   0,20

You can try to use a Dual-state button, see picture below (I think this type of button didn't exist in summer 2015 when this thread was started):


image


The 'val' attribute changes automatically between 0 and 1 when you press the button, so you can use this attribute to know the status of the button.


I tried your HMI file with the Debug window.

The image of the button changes if I send following code:

b0.pic=13

ref b0



In your CPP library file you have following code:

bool NexButton::setPic(uint32_t number)
{
    char buf[10] = {0};
    String cmd;
    
    utoa(number, buf, 10);
    cmd += getObjName();
    cmd += ".picc=";
    cmd += buf;

    sendCommand(cmd.c_str());
    return recvRetCommandFinished();
}

The setPic function sends following command: "b0.picc=13" 

with "picc" instead of "pic".

"picc" is used if attribute "sta"="crop image".

Here you have attribute "sta"="image", so you must use "pic".



So you must change the setPic function in the library:

- Change "picc" to "pic"

- Send command "ref b0"  ("ref " + getObjName())


@ITEAD

In an earlier thread ( http://support.iteadstudio.com/support/discussions/topics/1000058422 ) you wrote that you would give more information about which parameters/attributes need the "ref" command. Where can we find this information?

I tried and thanks it works. I didn't know I can change green attributes via serial.

And now I have another question. How can I send value of slider to serial? I want to send just character B (print B) and value of slider (one byte) and CRLF (printh 0d 0a). Is it possible?

 

I want to send just character B (print B) and value of slider (one byte) and CRLF (printh 0d 0a). Is it possible?
See this thread:
http://support.iteadstudio.com/support/discussions/topics/1000063242

Hello,


I am new to Nextion display and am trying to change the picture of a button when I 1 press it (picture green button) and second change the picture when I second press the button (red button) where the Arduino Uno than sends command to the output wich controls a relay. With that I would also like that the picture (crop q0) changes acordingly to red/green.


I suffered now for a couple of days with different code examples from the forums but nothing is working so I would realy be grathefull for a startup help to get it running. does anyone have a sample that works and the needed library changes. 


Thank you very much.


HMI
(332 KB)

Thanks! We have added the command "ref 0" in the wiki.


ref 0: refresh all components of the current page 

Remarks:

If you refresh one of the components,the component will be on the first top,but covers the others.Use this command "ref 0" will be work well.

Login or Signup to post a comment