Start a new topic

momentary buttons

How do I write code to turn on a relay when you push the button then on release it would turn off.


1 person likes this idea

Hi

you will have to do something with Touch PRESS / RELEASE event!

  a timer running when the time is equal

PNG
(20.1 KB)
I have the buttons set up, now about the timer part not sure what you mean. I have been trying different code for the arduino thru the examples but they are only on then push  off nothing momentary i try to adjust the code for what the parameters that i have but get errors 

 

Hi,

I've found the solution!

I do not agree with him, but with directions.

The solution I found in the file: NexTouch.h

equally good and logical thinking then you see it.

I like to hear when you've found it.

tell and I say yes or no

greeting Vic

I am still having trouble writing the code for this. I cant even get the pins to turn on or i get a compiler error . this is the code i am using now I cant get the pin to turn on now i need to tell it to turn off the pin after half a sec i just seem to get the code to work

 #include "Nextion.h"
#define PIN_stop 40


NexProgressBar j0 = NexProgressBar(1, 8, "j0");
NexButton pause = NexButton(1, 1, "pause");
NexButton play = NexButton(1, 2, "play");
NexButton backward = NexButton(1, 3, "backward");
NexButton stop = NexButton(1, 4, "stop");
NexButton forward = NexButton(1, 5, "forward");
NexButton home1 = NexButton(1, 6, "home1");
NexButton vup = NexButton(1, 9, "vup");
NexButton vdown = NexButton(1, 10, "vdown");


NexTouch *nex_listen_list[] =
{
&pause,
&play,
&backward,
&stop,
&forward,
&home1,
&vup,
&vdown,
NULL
};

void vupPopCallback(void *ptr)
{Serial.begin(9600);
uint32_t number = 8;
dbSerialPrintln("vupPopCallback");

j0.getValue(&number);

number += 1;
if (number >= 100)
{
number = 100;
}

j0.setValue(number);
}

void vdownPopCallback(void *ptr)
{
uint32_t number = 8;
dbSerialPrintln("vdownPopCallback");

j0.getValue(&number);

if (number >= 1)
{
number -= 1;
}

j0.setValue(number);
}

void stopPopCallback(void *ptr)
{
NexDSButton *btn = (NexDSButton *)ptr;
dbSerialPrintln("stopPopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr);
digitalWrite(40, HIGH);
}




void setup(void)
{
nexInit();
pinMode(40, OUTPUT);
vup.attachPop(vupPopCallback);
vdown.attachPop(vdownPopCallback);
stop.attachPop(stopPopCallback);
dbSerialPrintln("setup done");
}


void loop(void)
{

nexLoop(nex_listen_list);
}

 

Hi

you also have a HMI file?

please upload it 

yes this  it

 

HMI

1 person likes this

 

 #include "Nextion.h"
#define PIN_stop 49

NexProgressBar j0 = NexProgressBar(1, 8, "j0");
NexButton pause = NexButton(1, 1, "pause");
NexButton play = NexButton(1, 2, "play");
NexButton backward = NexButton(1, 3, "backward");
NexButton stop = NexButton(1, 4, "stop");
NexButton forward = NexButton(1, 5, "forward");
NexButton home1 = NexButton(1, 6, "home1");
NexButton vup = NexButton(1, 9, "vup");
NexButton vdown = NexButton(1, 10, "vdown");

char buffer[100] = {0};

NexTouch *nex_listen_list[] = 
{
&pause,
&play,
&backward,
&stop,
&forward,
&home1, 
&vup,
&vdown,
NULL
};

void vupPopCallback(void *ptr)
{Serial.begin(115200);
uint32_t number = 8;
dbSerialPrintln("vupPopCallback");

j0.getValue(&number);

number += 1;
if (number >= 100)
{
number = 100;
}

j0.setValue(number);
}

void vdownPopCallback(void *ptr)
{
uint32_t number = 8;
dbSerialPrintln("vdownPopCallback");

j0.getValue(&number);

if (number >= 1)
{
number -= 1;
}

j0.setValue(number);
}
void stopPopCallback(void *ptr)
{
NexButton *btn = (NexButton *)ptr;
dbSerialPrintln("stopPopCallback");
dbSerialPrint("ptr=");
dbSerialPrintln((uint32_t)ptr); 
digitalWrite(PIN_stop, HIGH);
}

void setup(void){
nexInit();
pinMode(PIN_stop, OUTPUT);
vup.attachPop(vupPopCallback);
vdown.attachPop(vdownPopCallback);
stop.attachPop(stopPopCallback);
dbSerialPrintln("setup done");
}

void loop(void){
  if   
   (PIN_stop,  HIGH);
  {
delay (500);
  digitalWrite (PIN_stop, LOW);
  }  
nexLoop(nex_listen_list);
}

 It's a little successful.

I have applied the rules 78 to 84.

I [digital write (PIN_stop, LOW)] instead of [digital write (40, LOW)] will see similar to what pin it goes.

On screen, I only use Touch RELEASE Event.

Using DELAY is not recommended better you can use Blink without delay.

For examples https://codebender.cc/ and search Duiker_vic and more also see suchthat total costs by: https://forum.arduino.cc/ in more languages.

greeting Vic

Login or Signup to post a comment