Documentation
For Arduino users
CompGpio.ino
1 #include "Nextion.h"
2 
3 NexGpio gpio;
4 NexNumber n0 = NexNumber(0,1,"n0");
5 NexNumber n1 = NexNumber(0,3,"n1");
6 
7 #define GPIO_PUSH_PORT 1
8 #define GPIO_PWM_PORT 2
9 #define GPIO_PUSH_OUTPUT_MODE 2
10 #define GPIO_PWM_OUT_MODE 3
11 #define CONTROLS_ID 0 //when the modeel is 1 to be valid
12 
13 uint32_t pwm_value = 0;
14 
15 void setup()
16 {
17  nexSerial.begin(115200);
18  gpio.pin_mode(GPIO_PUSH_PORT,GPIO_PUSH_OUTPUT_MODE,CONTROLS_ID);
19  gpio.pin_mode(GPIO_PWM_PORT,GPIO_PWM_OUT_MODE,CONTROLS_ID);
20 }
21 
22 void loop()
23 {
24  if(gpio.digital_read(1) == 0)
25  {
26  gpio.digital_write(GPIO_PUSH_PORT,HIGH);
27  n0.setValue(1);
28  }
29  else
30  {
31  gpio.digital_write(GPIO_PUSH_PORT,LOW);
32  n0.setValue(0);
33  }
34 
35 
36  gpio.analog_write(GPIO_PWM_PORT,pwm_value);
37  n1.setValue(pwm_value);
38  if(pwm_value == 100)
39  {
40  pwm_value = 0;
41  }
42  else
43  {
44  pwm_value += 20;
45  }
46 
47  delay(1000);
48 }
NexNumber component.
Definition: NexNumber.h:30
#define nexSerial
Define nexSerial for communicate with Nextion touch panel.
Definition: NexConfig.h:37
bool digital_write(uint32_t port, uint32_t value)
write a HIGH or a LOW value to a digital pin
Definition: NexGpio.cpp:37
bool pin_mode(uint32_t port, uint32_t mode, uint32_t control_id)
Set gpio mode.
Definition: NexGpio.cpp:17
The header file including all other header files provided by this library.
NexGpio component.
Definition: NexGpio.h:31
bool setValue(uint32_t number)
Set number attribute of component.
Definition: NexNumber.cpp:31
bool analog_write(uint32_t port, uint32_t value)
writes an analog value (PWM wave) to a pin
Definition: NexGpio.cpp:68
uint32_t digital_read(uint32_t port)
read a HIGH or a LOW value to a digital pin
Definition: NexGpio.cpp:53