Help !callback turn off espalexa

Good morning, I'm doing a project, but I'm new to programming and I'm having trouble getting Espalexa's callback to go back to the off state

do not notice the programming because I believe that they are not very correct

#include <HX711_ADC.h> // need to install

#include <Wire.h>

#include <LiquidCrystal_I2C.h> // need to install

#define pinCem_gramas 18

#define pinCinquenta_gramas 19

#define pinLed 13

#define pin_motor 5

#ifdef ARDUINO_ARCH_ESP32

#include <WiFi.h>

#else

#include <ESP8266WiFi.h>

#endif

#include <Espalexa.h>

HX711_ADC LoadCell(26,25); // parameters: dt pin 6, sck pin 7;

LiquidCrystal_I2C lcd(0x27, 16,2); // 0x27 is the i2c address might different;you can check with Scanner

float peso ;

float LIG ;

/*

* This is a basic example on how to use Espalexa and its device declaration methods.

*/

#ifdef ARDUINO_ARCH_ESP32

#include <WiFi.h>

#else

#include <ESP8266WiFi.h>

#endif

#include <Espalexa.h>

// prototypes

boolean connectWifi();

//callback functions

void firstLightChanged(uint8_t brightness);

void secondLightChanged(uint8_t brightness);

void thirdLightChanged(uint8_t brightness);

// Change this!!

const char* ssid = "";

const char* password = "";

boolean wifiConnected = false;

Espalexa espalexa;

//EspalexaDevice* device3; //this is optional

EspalexaDevice* device3;

String Device_1_Name = "Cem";

String Device_2_Name = "Cinquenta_gramas";

void setup()

{

LoadCell.begin(); // start connection to HX711

LoadCell.start(2000); // load cells gets 2000ms of time to stabilize

LoadCell.setCalFactor(5285.46); // calibration factor for load cell => dependent on your individual setup

lcd.init();

lcd.backlight();

pinMode( pinCem_gramas, OUTPUT);

pinMode( pinCinquenta_gramas, OUTPUT);

pinMode( pinLed, OUTPUT);

pinMode( pin_motor, OUTPUT);

Serial.begin(115200);

// Initialise wifi connection

while (! connectWifi () ) {

}

digitalWrite (pinLed, HIGH) ;

// Define your devices here.

espalexa.addDevice("Cem_gramas", firstLightChanged,0); //simplest definition, default state off

espalexa.addDevice("Cinquenta_gramas", secondLightChanged, 0); //third parameter is beginning state (here fully on)

device3 = new EspalexaDevice("Light_3", thirdLightChanged); //you can also create the Device objects yourself like here

espalexa.addDevice(device3); //and then add them

device3->setValue(128);

//LIG =device3->setValue(0); //this allows you to e.g. update their state value at any time!

espalexa.begin();

} //else

//while (1) {

//Serial.println("Cannot connect to WiFi. Please check data and reset the ESP.");

//delay(2500);

void loop()

{

espalexa.loop();

Serial.print ("Peso ");

Serial.print (LoadCell.getData(), 3);

peso = LoadCell.getData();

LoadCell.update(); // retrieves data from the load cell

float peso = LoadCell.getData(); // get output value

lcd.setCursor(0, 0); // set cursor to first row

lcd.print("Weight[g]:"); // print out to LCD

lcd.setCursor(0, 1); // set cursor to second row

lcd.print(peso); // print out the retrieved value to the second row

if(peso > 100)

{

digitalWrite(pin_motor,LOW);

Serial.println("OFF");

}

delay(1);

}

//our callback functions

void firstLightChanged(uint8_t brightness) {

Serial.print("Device 1 changed to ");

//do what you need to do here

//EXAMPLE

if (brightness) {

Serial.print("ON, brightness ");

Serial.println(brightness);

digitalWrite (pinCem_gramas, 255) ;

digitalWrite (pin_motor, 255) ;

}

else {

Serial.println("OFF");

digitalWrite (pinCem_gramas, LOW) ;

digitalWrite (pin_motor, LOW) ;

}

}

void secondLightChanged(uint8_t brightness) {

if (brightness) {

Serial.print("ON, brightness ");

Serial.println(brightness);

digitalWrite (pinCinquenta_gramas, HIGH) ;

}

else {

Serial.print("OFF, brightness ");

Serial.println(brightness);

Serial.println("OFF");

digitalWrite (pinCinquenta_gramas, LOW) ;

}

//do what you need to do here

}

//do what you need to do here

void thirdLightChanged(uint8_t brightness) {

//do what you need to do here

}

// connect to wifi – returns true if successful or false if not

boolean connectWifi(){

boolean state = true;

int i = 0;

WiFi.mode(WIFI_STA);

WiFi.begin(ssid, password);

Serial.println("");

Serial.println("Connecting to WiFi");

// Wait for connection

Serial.print("Connecting...");

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

if (i > 20){

state = false; break;

}

i++;

}

Serial.println("");

if (state){

Serial.print("Connected to ");

Serial.println(ssid);

Serial.print("IP address: ");

Serial.println(WiFi.localIP());

}

else {

Serial.println("Connection failed.");

}

return state;

}





here my problem 



if(weight > 100)
{
digitalWrite(pin_motor,LOW);
Serial.println("OFF");
}

on line 121 to 124 I need that after I have the weight information, turn off the calback firstLightChanged

Why? You can react on that event by changing the instructions inside firstLightChanged(). At the moment your code doesn't do anything there so you don't have to change it.

I tried to change the instructions inside the first changed but without success, can you help me with this block? I want when executing this function the firstchangelight would go back to off (0

I would like after this function the firstlightchanged to go back to the off state (==0).

if(weight > 100)
{
digitalWrite(pin_motor,LOW);
Serial.println("OFF");
}


If that code doesn't work, your hardware might not be represented in the code. As we have no clue about your hardware (you failed to post a wiring diagram and links to the used hardware) we cannot check that.
That code does set pin 5 to GND if the weight variable (which wasn't in your original code) is greater than 100.