CompGpio.ino
#include "Nextion.h"
NexGpio gpio;
NexNumber n0 = NexNumber(0,1,"n0");
NexNumber n1 = NexNumber(0,3,"n1");
#define GPIO_PUSH_PORT 1
#define GPIO_PWM_PORT 2
#define GPIO_PUSH_OUTPUT_MODE 2
#define GPIO_PWM_OUT_MODE 3
#define CONTROLS_ID 0 //when the modeel is 1 to be valid
uint32_t pwm_value = 0;
void setup()
{
nexSerial.begin(115200);
gpio.pin_mode(GPIO_PUSH_PORT,GPIO_PUSH_OUTPUT_MODE,CONTROLS_ID);
gpio.pin_mode(GPIO_PWM_PORT,GPIO_PWM_OUT_MODE,CONTROLS_ID);
}
void loop()
{
if(gpio.digital_read(1) == 0)
{
gpio.digital_write(GPIO_PUSH_PORT,HIGH);
n0.setValue(1);
}
else
{
gpio.digital_write(GPIO_PUSH_PORT,LOW);
n0.setValue(0);
}
gpio.analog_write(GPIO_PWM_PORT,pwm_value);
n1.setValue(pwm_value);
if(pwm_value == 100)
{
pwm_value = 0;
}
else
{
pwm_value += 20;
}
delay(1000);
}
NexNumber
NexNumber component.
Definition: NexNumber.h:30
nexSerial
#define nexSerial
Define nexSerial for communicate with Nextion touch panel.
Definition: NexConfig.h:37
NexGpio::digital_write
bool digital_write(uint32_t port, uint32_t value)
write a HIGH or a LOW value to a digital pin
Definition: NexGpio.cpp:37
NexGpio::pin_mode
bool pin_mode(uint32_t port, uint32_t mode, uint32_t control_id)
Set gpio mode.
Definition: NexGpio.cpp:17
Nextion.h
The header file including all other header files provided by this library.
NexGpio
NexGpio component.
Definition: NexGpio.h:31
NexNumber::setValue
bool setValue(uint32_t number)
Set number attribute of component.
Definition: NexNumber.cpp:31
NexGpio::analog_write
bool analog_write(uint32_t port, uint32_t value)
writes an analog value (PWM wave) to a pin
Definition: NexGpio.cpp:68
NexGpio::digital_read
uint32_t digital_read(uint32_t port)
read a HIGH or a LOW value to a digital pin
Definition: NexGpio.cpp:53