WS_GPIO.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "WS_GPIO.h"
  2. /************************************************************* I/O *************************************************************/
  3. void RGB_Light(uint8_t red_val, uint8_t green_val, uint8_t blue_val)
  4. {
  5. neopixelWrite(GPIO_PIN_RGB,green_val,red_val,blue_val); // RGB color adjustment
  6. }
  7. void Buzzer_PWM(uint16_t Time) //ledChannel:PWM Channe dutyfactor:dutyfactor
  8. {
  9. ledcWrite(PWM_Channel, Dutyfactor);
  10. delay(Time);
  11. ledcWrite(PWM_Channel, 0);
  12. }
  13. int relays[6] = { GPIO_PIN_CH1, GPIO_PIN_CH2, GPIO_PIN_CH3, GPIO_PIN_CH4, GPIO_PIN_CH5, GPIO_PIN_CH6 };
  14. void TriggerRelay(int relay, bool closed)
  15. {
  16. digitalWrite(relays[relay], closed ? HIGH : LOW);
  17. }
  18. bool RelayStatus(int relay)
  19. {
  20. return digitalRead(relays[relay] > 0);
  21. }
  22. bool IsOverride()
  23. {
  24. return digitalRead(GPIO_OVERRIDE > 0);
  25. }
  26. void GPIO_Init()
  27. {
  28. /*************************************************************************
  29. Relay GPIO
  30. *************************************************************************/
  31. for (int i=0; i<6; i++)
  32. pinMode(relays[i], OUTPUT);
  33. pinMode(GPIO_OVERRIDE, INPUT);
  34. pinMode(GPIO_PIN_RGB, OUTPUT); // Initialize the control GPIO of RGB
  35. pinMode(GPIO_PIN_Buzzer, OUTPUT); // Initialize the control GPIO of Buzzer
  36. ledcSetup(PWM_Channel, Frequency, Resolution); // Set a LEDC channel
  37. ledcAttachPin(GPIO_PIN_Buzzer, PWM_Channel); // Connect the channel to the corresponding pin
  38. }