WS_GPIO.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include "WS_GPIO.h"
  2. /************************************************************* I/O *************************************************************/
  3. void digitalToggle(int pin)
  4. {
  5. digitalWrite(pin, !digitalRead(pin)); // Toggle the state of the pin
  6. }
  7. void RGB_Light(uint8_t red_val, uint8_t green_val, uint8_t blue_val)
  8. {
  9. neopixelWrite(GPIO_PIN_RGB,green_val,red_val,blue_val); // RGB color adjustment
  10. }
  11. void Buzzer_PWM(uint16_t Time) //ledChannel:PWM Channe dutyfactor:dutyfactor
  12. {
  13. ledcWrite(PWM_Channel, Dutyfactor);
  14. delay(Time);
  15. ledcWrite(PWM_Channel, 0);
  16. }
  17. void GPIO_Init()
  18. {
  19. /*************************************************************************
  20. Relay GPIO
  21. *************************************************************************/
  22. pinMode(GPIO_PIN_CH1, OUTPUT); // Initialize the control GPIO of relay CH1
  23. pinMode(GPIO_PIN_CH2, OUTPUT); // Initialize the control GPIO of relay CH2
  24. pinMode(GPIO_PIN_CH3, OUTPUT); // Initialize the control GPIO of relay CH3
  25. pinMode(GPIO_PIN_CH4, OUTPUT); // Initialize the control GPIO of relay CH4
  26. pinMode(GPIO_PIN_CH5, OUTPUT); // Initialize the control GPIO of relay CH5
  27. pinMode(GPIO_PIN_CH6, OUTPUT); // Initialize the control GPIO of relay CH6
  28. pinMode(GPIO_PIN_RGB, OUTPUT); // Initialize the control GPIO of RGB
  29. pinMode(GPIO_PIN_Buzzer, OUTPUT); // Initialize the control GPIO of Buzzer
  30. ledcSetup(PWM_Channel, Frequency, Resolution); // Set channel
  31. ledcAttachPin(GPIO_PIN_Buzzer, PWM_Channel); // Connect the channel to the corresponding pin
  32. }