Start a new topic

Button does not work, help

Can someone give me a hand?

I have this code below, it works the functions below, plus the button function does not run, and if the functions of the functions more, the buttons does not fire, when I delete the nextion lines (text, gauger etc) the button works again More when I re-trigger these functions, the button on the nextion stops working should be some call.

 

Thanks, follow code below, use arduino mega ide 1.8.0, nextion 3.2 embedded.

 

#include <doxygen.h>

#include <NexButton.h>

#include <NexCheckbox.h>

#include <NexConfig.h>

#include <NexCrop.h>

#include <NexDualStateButton.h>

#include <NexGauge.h>

#include <NexGpio.h>

#include <NexHardware.h>

#include <NexHotspot.h>

#include <NexNumber.h>

#include <NexObject.h>

#include <NexPage.h>

#include <NexPicture.h>

#include <NexProgressBar.h>

#include <NexRadio.h>

#include <NexRtc.h>

#include <NexScrolltext.h>

#include <NexSlider.h>

#include <NexText.h>

#include <NexTimer.h>

#include <Nextion.h>

#include <NexTouch.h>

#include <NexUpload.h>

#include <NexVariable.h>

#include <NexWaveform.h>

#include <EmonLib.h>

#include "Nextion.h"

 

NexProgressBar j3 = NexProgressBar (0, 3, "j3"); // nextion id progress bar

NexGauge pointer = NexGauge (2, 3, "z0"); // nextion id gauger

NexNumber voltsmostra = NexNumber (6, 6, "volt1"); // nextion id number voltmeter

NexButton MCUside_b0 = NexButton (5,1, "b0");

NexText t0 = NexText (0, 0, "t0"); // nextion id text logo

 

 

 

 

 

Int pot = 0;

Int pot1 = 1;

Int fan = 22;

Int tempalta = 23;

Int diesel level = 24;

Int powerongenerator = 25;

Const int poweron = 7;

Int buttonState = 0;

Char buffer [100] = {0};

Int msgdiesel = 26;

Int f = 0;

Int msgpower = 27;

Int msgtemp = 28;

Int botaostop = 29;

 

Void ButtonPressedCallback (void * ptr)

{

  DigitalWrite (botaostop, LOW);

  Serial.print ("tight-knob");

}

 

Void ButtonReleasedCallback (void * ptr)

{

  DigitalWrite (botaostop, HIGH);

  Serial.print ("loose button");

}

NexTouch * nex_listen_list [] = {

 

  & MCUside_b0,

  & T0,

  NULL

 

};

 

 Void setup (void) {

 

 NexInit ();

 MCUside_b0.attachPush (ButtonPressedCallback, & MCUside_b0);

 MCUside_b0.attachPop (ButtonReleasedCallback, & MCUside_b0);

 Serial.begin (115600);

 PinMode (fan, OUTPUT);

 PinMode (tempalta, OUTPUT);

 PinMode (diesel level, OUTPUT);

 PinMode (powerongenerator, OUTPUT);

 PinMode (poweron, INPUT);

 PinMode (msgdiesel, OUTPUT);

 PinMode (msgpower, OUTPUT);

 PinMode (msgtemp, OUTPUT);

 PinMode (botaostop, OUTPUT);

}

 

Void loop (void) {

NexLoop (nex_listen_list);

temperature();

diesel();

External signal ();

 

}

 

 

Void temperature () {

 

Int sensorValue = analogRead (pot);

Int psi = map (sensorValue, 120, 1023, 0, 90);

//j3.setValue(psi);

// nalogWrite (fan, sensorValue / 5);

If (sensorValue <600) digitalWrite (fan, LOW); // set the LED on

  Else digitalWrite (fan, HIGH); // set the LED on

 

If (sensorValue <1000) {

DigitalWrite (tempalta, LOW);

DigitalWrite (msgtemp, LOW);

}

  Else

 {

DigitalWrite (tempalta, HIGH);

DigitalWrite (msgtemp, HIGH);

}

}

 

Void diesel () {

Int sensordiesel = analogRead (pot1);

Int tank = map (sensordiesel, 120, 1023, 130, 250);

//pointer.setValue(tank);

If (sensordiesel> 800) {

DigitalWrite (diesel level, HIGH);

DigitalWrite (msgdiesel, HIGH);

 

}

  Else

 

  {

   DigitalWrite (diesel level, LOW);

   DigitalWrite (msgdiesel, LOW);

}

}

 

 Void external signal () {

 ButtonState = digitalRead (poweron);

 If (buttonState == HIGH) {

    DigitalWrite (powerongenerator, HIGH);

    T0.setText ("LACK PRIMARY NETWORK !!");

    DigitalWrite (msgpower, HIGH);

  }

  Else

  {

    DigitalWrite (powerongenerator, LOW);

    DigitalWrite (msgpower, LOW);

    T0.setText ("PRIMARY NETWORK OK");

  }

}

1 Comment

Please look around the last 20 posts in Free Chat

http://support.iteadstudio.com/discussions/topics/11000011561


I know I have just recently dealt with overloading of loop()

When too much become on serial, button will have no way of being heard

You must not overload your loop.

Login or Signup to post a comment