esp32触摸和LED灯显示

esp32触摸和LED灯显示
调用模拟analogwrite_esp32库
调用oneButton库
调用Simplertimer库


#include 
#include 
#include 
#include 

volatile int alllight;
volatile int halflight;
volatile int offflight;
OneButton button23(23,true);   //按键GPIO
SimpleTimer timer;

void gotTouch4() {
  Serial.println("led1  detected");
  analogWrite(19, alllight);
  analogWrite(18, halflight);
  analogWrite(5, halflight);
  timer.setTimer(12000, super_delay_function2, 1);
}

void gotTouch27() {
  Serial.println("led2  detected");
  analogWrite(19, halflight);
  analogWrite(18, alllight);
  analogWrite(5, halflight);
  timer.setTimer(12000, super_delay_function2, 1);
}

void gotTouch12() {
  Serial.println("led3  detected");
  analogWrite(19, halflight);
  analogWrite(18, halflight);
  analogWrite(5, alllight);
  timer.setTimer(12000, super_delay_function2, 1);
}

void attachClick23() {
  analogWrite(22, alllight);
  Serial.println("button  detected");
  timer.setTimer(9000, super_delay_function1, 1);
}

void super_delay_function2() {
analogWrite(19, offflight);
  analogWrite(18, offflight);
  analogWrite(5, offflight);
  Serial.println("touch led off");
}

void super_delay_function1() {
analogWrite(22, offflight);
  Serial.println("button led off");
}

void setup(){
  alllight = 255;
  halflight = 120;
  offflight = 0;
  Serial.begin(115200);
  touchAttachInterrupt(4,gotTouch4, 8);
  touchAttachInterrupt(27,gotTouch27, 8);
  touchAttachInterrupt(12,gotTouch12, 8);
  vTaskDelay(3000);
  for (int i = 1; i <= 9; i = i + (1)) {
    analogWrite(19, offflight);
    analogWrite(18, offflight);
    analogWrite(5, offflight);
    vTaskDelay(300);
    analogWrite(19, alllight);
    analogWrite(18, alllight);
    analogWrite(5, alllight);
    vTaskDelay(300);
  }
  Serial.println("flash over");
  button23.attachClick(attachClick23);
}

void loop(){
  button23.tick();
  timer.run();
}


你可能感兴趣的:(arduino,随笔)