想用(D7)中间继电器控制加热设备,(A0)输入,板(D9)led,板(D4)button
程序
- /*!
- *
- *
- *
- */
- // 动态变量
- #define button1 D4 //触摸按键接口定义IO27/D4
- #define LED_DT D9 // Arduino输出控制信号引脚IO2/D9
- #define OUT_PWM D7 // Arduino输出控制信号引脚IO13/D7
- #define IN_0 A0 // Arduino输入控制信号引脚IO36/A0
- #define KEYA_SPEED1 50 //长按的时间长度(单位10mS) 总共1s 100
- #define KEYA_SPEED2 10 //双击的时间长度(单位20mS) 200ms双击间隔
- volatile uint8_t b; //长按判断标志位
- volatile uint8_t openState=1;//灯效模式,默认关灯。单击openState = 0;双击openState = 1;长按openState = 2;
- volatile bool a=0,c=0,s=0; //刚刚结束滑动标志
- uint64_t chipid;
- unsigned long startProducing, endProducing;
- volatile float mind_n_key1, mind_n_all, mind_n_oninall;
- // 函数声明
- void buttonACallback();
- void DF_C();
- void DF_B();
- void DF_onoff(uint16_t mind_n_on, uint16_t mind_n_off, uint8_t mind_n_key);
- void DF_A();
- void button_State()
- {
- //A
- if(!(digitalRead(button1))){ //检测按键是否按下
- delay(20); //延时去抖动
- if(!(digitalRead(button1))){//判断长短键
- while((!(digitalRead(button1)))&&(c
- c++;delay(10); //长按判断的计时
- Serial.printf("A键按 %dn",c);//
- }
- if(c>=KEYA_SPEED1){ //长键处理 循环100次为长按1s
- //长按后执行的程序放到此处
-
- openState = 2;
-
- Serial.println("A键长按 rn");
- while(!(digitalRead(button1)));//等待按键松开
- }
- else{ //单击处理 按键A松开后
-
- if(a==0){
- for(b=0;b
- delay(20);
- if(!(digitalRead(button1))){//判断200ms内是否再次按下
- a=1;
- //双击后执行的程序放到此处
-
- openState = 1;
-
- Serial.println("A键双击 rn");
- }
- }
-
- if(a==0){ //判断单击
- if(s==1){ //判断是不是刚执行完滑动操作
- s=0; //如果是则本次不执行单击处理(因为是滑动的放开操作)
- }
- else{ //如果不是,则正常执行单击处理
- //单击后执行的程序放到此处
-
- openState = 0;
-
- Serial.println("A键单击 rn");
- }
- }
- }
- }
- a=0;c=0; //参数清0
- }
- } //按键判断在此结束
- }
- // 主程序开始
- void setup() {
- pinMode(OUT_PWM, OUTPUT);
- pinMode(LED_DT, OUTPUT);
- pinMode(IN_0, INPUT);
- digitalWrite(OUT_PWM, LOW);//io14/d6
- // onEvent(ID_BUTTON_A, PRESS, buttonACallback);
- Serial.begin(115200);
- Serial.println("");
- delay(1000);
- pinMode(button1,INPUT_PULLUP);
- mind_n_key1 = 0;
- Serial.print("Setup: Executing on core ");
- Serial.println(xPortGetCoreID());
- chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
- Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes
- Serial.printf("%08Xn",(uint32_t)chipid);//print Low 4bytes.
-
- // Serial.printf("total heap size = %un",ESP.getHeapSize());
- Serial.printf("available heap = %un",ESP.getFreeHeap());
- // Serial.printf("lowest level of free heap since boot = %un",ESP.getMinFreeHeap());
- // Serial.printf("largest block of heap that can be allocated at once = %un",ESP.getMaxAllocHeap());
- // Serial.printf("total Psram size = %un",ESP.getPsramSize());
- // Serial.printf("available Psram = %un",ESP.getFreePsram());
- // Serial.printf("lowest level of free Psram since boot = %un",ESP.getMinFreePsram());
- // Serial.printf("largest block of Psram that can be allocated at once = %un",ESP.getMinFreePsram());
- Serial.printf("get Chip Revision = %un",ESP.getChipRevision());// uint8_t getChipRevision() 返回芯片版本号;
- Serial.printf("getCpuFreqMHz = %un",ESP.getCpuFreqMHz());// uint8_t getCpuFreqMHz() 返回芯片时钟频率;
- Serial.printf("get Cycle Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- Serial.printf("get SdkVersion = %sn",ESP.getSdkVersion());//const char * getSdkVersion() 返回SDK版本号;
- xTaskCreate(
- DF_A, /* Task function. */
- "DF_A", /* String with name of task. */
- 20000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
- xTaskCreate(
- buttonACallback, /* Task function. */
- "buttonA", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 3, /* Priority of the task. */
- NULL);
- }
- void loop() {
- delay(3000);
- // Serial.print("Main Loop: Executing on core ");
- // Serial.println(xPortGetCoreID());
- // Serial.print("button1: ");
- // Serial.println((digitalRead(button1)));
- // Serial.print("LED_DT: ");
- // Serial.println((digitalRead(LED_DT)));
- // digitalWrite(LED_DT, HIGH); // turn the LED on (HIGH is the voltage level)
- // delay(1000); // wait for a second
- // digitalWrite(LED_DT, LOW); // turn the LED off by making the voltage LOW
- digitalWrite(LED_DT, 1 ^ digitalRead(LED_DT)); //翻转 输出电平
- }
- // 自定义函数
- void DF_C(void * parameter) {
- Serial.print("Created task DF_c: Executing on core ");
- Serial.println(xPortGetCoreID());
- while (!(mind_n_key1<2)) {
- digitalWrite(OUT_PWM, LOW);
- delay(6);
- }
- if ((mind_n_key1==0)) {
-
- xTaskCreate(
- DF_A,
- "DF_A", /* String with name of task. */
- 20000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- if ((mind_n_key1==1)) {
-
- xTaskCreate(
- DF_B,
- "DF_B", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- Serial.println("删除DF_c");
- vTaskDelete( NULL ); //任务的删除
- }
- void DF_B(void * parameter) {
- Serial.print("Created task DF_b: Executing on core ");
- Serial.println(xPortGetCoreID());
- while (!((mind_n_key1==0) || (mind_n_key1==2))) {
- DF_onoff((analogRead(IN_0)), 1023, 1);
- }
- if ((mind_n_key1==0)) {
-
- xTaskCreate(
- DF_A,
- "DF_A", /* String with name of task. */
- 20000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- if ((mind_n_key1==2)) {
-
- xTaskCreate(
- DF_C,
- "DF_C", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- Serial.println("删除DF_b");
- vTaskDelete( NULL ); //任务的删除
-
- }
- void DF_onoff(uint16_t mind_n_on, uint16_t mind_n_off, uint8_t mind_n_key) {
-
- while (!(mind_n_off==0)) {
- while (!(mind_n_on==0)) {
- digitalWrite(OUT_PWM, HIGH);
- delay(6);
- mind_n_off -= 1;
- mind_n_on -= 1;
- if (!(mind_n_key==mind_n_key1)) {
- mind_n_off = 1;
- mind_n_on = 1;
- }
- }
- if ((mind_n_off>0)) {
- digitalWrite(OUT_PWM, LOW);
- delay(6);
- mind_n_off -= 1;
- if (!(mind_n_key==mind_n_key1)) {
- mind_n_off = 1;
- mind_n_on = 1;
- }
- }
- }
- }
- void DF_A(void * parameter) {
- uint8_t mind_n_As1 = 24;
- uint8_t mind_n_Asn = 80;
- Serial.print("Created task DF_A: Executing on core ");
- Serial.println(xPortGetCoreID());
- startProducing = millis();//开始时间
- // Serial.printf("DF_A start Cycle Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- //Serial.println("");
- // Serial.printf(" millis %u start n",startProducing );//
- while (!(mind_n_As1==0)) {
- DF_onoff(1023, 1023, 0);
- // Serial.printf("DF_A start Cycle Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- //Serial.println("");
- // Serial.printf(" millis: %u n",(millis()-startProducing ));//
- //Serial.println("");
- if ((mind_n_key1==0)) {
- mind_n_As1 -= 1;
- }
- else {
- mind_n_As1 = 1;
- mind_n_Asn = 1;
- }
- // Serial.printf(" mind_n_As1: %u n",mind_n_As1);//
- //Serial.println("");
- }
- Serial.printf("DF_A 50% start Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- Serial.println("");
- while (!(mind_n_Asn==0)) {
- DF_onoff(490, 1023, 0);
- if ((mind_n_key1==0)) {
- mind_n_Asn -= 1;
- }
- else {
- mind_n_As1 = 0;
- mind_n_Asn = 1;
- }
- }
- // Serial.printf("DF_A end Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- //Serial.println("");
- endProducing = millis();//结束时间
- Serial.print("Producing time all时间(ms): ");
- Serial.println(( endProducing - startProducing));//写入耗费时间(ms)
- if ((mind_n_key1==0)) {
- mind_n_key1 = 2;
- }
- if ((mind_n_key1==1)) {
-
- xTaskCreate(
- DF_B,
- "DF_B", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- if ((mind_n_key1==2)) {
-
- xTaskCreate(
- DF_C,
- "DF_C", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- Serial.println("删除DF_A");
- vTaskDelete( NULL ); //任务的删除
- }
- // 事件回调函数
- void buttonACallback(void * parameter) {
- Serial.print("Created task buttonA: Executing on core ");
- Serial.println(xPortGetCoreID());
- while(1){
- button_State();
- if ((openState==0)) {
- mind_n_key1 += 1;
- openState=1;
- if ((mind_n_key1>2)) {
- mind_n_key1 = 0;
- }
- }
- delay(150);
- }
- }
复制代码
上传
项目使用了 217095 字节,占用了 (10%) 程序存储空间。最大为 2097152 字节。
全局变量使用了24332字节,(8%)的动态内存,余留270580字节局部变量。最大为294912字节。
esptool.py v2.0-dev
Connecting...
Uploading stub...
Running stub...
Stub running...
Attaching SPI flash...
Configuring flash size...
Compressed 8752 bytes to 5467...
Writing at 0x00001000... (100 %)
Wrote 8752 bytes (5467 compressed) at 0x00001000 in 0.5 seconds (effective 143.5 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 105...
Writing at 0x00008000... (100 %)
Wrote 3072 bytes (105 compressed) at 0x00008000 in 0.0 seconds (effective 1293.5 kbit/s)...
Hash of data verified.
Compressed 8192 bytes to 47...
Writing at 0x0000e000... (100 %)
Wrote 8192 bytes (47 compressed) at 0x0000e000 in 0.0 seconds (effective 4096.0 kbit/s)...
Hash of data verified.
Compressed 305168 bytes to 133261...
Writing at 0x00010000... (11 %)
Writing at 0x00014000... (22 %)
Writing at 0x00018000... (33 %)
Writing at 0x0001c000... (44 %)
Writing at 0x00020000... (55 %)
Writing at 0x00024000... (66 %)
Writing at 0x00028000... (77 %)
Writing at 0x0002c000... (88 %)
Writing at 0x00030000... (100 %)
Wrote 305168 bytes (133261 compressed) at 0x00010000 in 11.7 seconds (effective 208.6 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting...
c om信息
15:00:53.390 -> load?ets Jul 29 2019 12:21:46
15:00:53.390 ->
15:00:53.390 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
15:00:53.390 -> configsip: 0, SPIWP:0x00
15:00:53.390 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
15:00:53.390 -> mode:DIO, clock div:2
15:00:53.390 -> load:0x3fff0008,len:8
15:00:53.390 -> load:0x3fff0010,len:1760
15:00:53.390 -> load:0x40078000,len:6668
15:00:53.390 -> load:0x40080000,len:252
15:00:53.390 -> entry 0x40080034
15:00:53.590 ->
15:00:54.590 -> Setup: Executing on core 1
15:00:54.590 -> ESP32 Chip ID = 944D8CBE5BC4
15:00:54.590 -> available heap = 219700
15:00:54.590 -> get Chip Revision = 1
15:00:54.590 -> getCpuFreqMHz = 240
15:00:54.590 -> get Cycle Count = 254537114
15:00:54.630 -> get SdkVersion = v2.0-rc1-803-g1e0710f1
15:00:54.630 -> Created task buttonA: Executing on core 1
15:00:54.630 -> Created task DF_A: Executing on core Main Loop: Executing on core 0
15:00:54.630 -> DF_A start Cycle Count = 258000783
15:00:54.630 ->
15:00:54.630 -> 1
15:01:04.630 -> Main Loop: Executing on core 1
15:01:14.630 -> Main Loop: Executing on core 1
15:01:24.620 -> Main Loop: Executing on core 1
15:01:34.601 -> Main Loop: Executing on core 1
15:01:44.611 -> Main Loop: Executing on core 1
15:01:54.618 -> Main Loop: Executing on core 1
15:02:04.618 -> Main Loop: Executing on core 1
15:02:14.618 -> Main Loop: Executing on core 1
15:02:24.618 -> Main Loop: Executing on core 1
15:02:34.618 -> Main Loop: Executing on core 1
15:02:44.618 -> Main Loop: Executing on core 1
15:02:54.608 -> Main Loop: Executing on core 1
15:03:04.638 -> Main Loop: Executing on core 1
15:03:14.618 -> Main Loop: Executing on core 1
15:03:24.618 -> Main Loop: Executing on core 1
15:03:28.058 -> Guru Meditation Error of type LoadProhibited occurred on core 1. Exception was unhandled.
15:03:28.058 -> Register dump:
15:03:28.058 -> PC : 0x400014fd PS : 0x00060c30 A0 : 0x800d3fb0 A1 : 0x3ffcd230
15:03:28.098 -> A2 : 0xa289a144 A3 : 0xa289a140 A4 : 0x000000ff A5 : 0x0000ff00
15:03:28.098 -> A6 : 0x00ff0000 A7 : 0xff000000 A8 : 0x00000000 A9 : 0x3ffc0b70
15:03:28.098 -> A10 : 0x00000003 A11 : 0x00060e23 A12 : 0x00060e20 A13 : 0x0000ff00
15:03:28.098 -> A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000012 EXCCAUSE: 0x0000001c
15:03:28.098 -> EXCVADDR: 0xa289a144 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
有
Guru Meditation Error of type LoadProhibited occurred on core 1. Exception was unhandled.
错误
网上查
Guru Meditation 错误
LoadProhibited,StoreProhibited(禁止加载,禁止存储)
当应用程序尝试读取或写入无效的内存位置时,会发生此 CPU 异常. 写入/读取的地址可在寄存器转储中的 EXCVADDR 寄存器中找到. 如果此地址为零,则通常表示应用程序尝试取消引用 NULL 指针. 如果此地址接近于零,则通常意味着应用程序尝试访问结构的成员,但指向该结构的指针为 NULL. 如果该地址是别的(垃圾值,不在 0x3fxxxxxx - 0x6xxxxxxx 范围内),则可能意味着用于访问数据的指针未初始化或已损坏.
更改程序,
- /*!
- *
- *
- *
- */
- // 动态变量
- #define button1 D4 //触摸按键接口定义IO27/D4
- #define LED_DT D9 // Arduino输出控制信号引脚IO2/D9
- #define OUT_PWM D7 // Arduino输出控制信号引脚IO13/D7
- #define IN_0 A0 // Arduino输入控制信号引脚IO36/A0
- #define KEYA_SPEED1 50 //长按的时间长度(单位10mS) 总共1s 100
- #define KEYA_SPEED2 10 //双击的时间长度(单位20mS) 200ms双击间隔
- volatile uint8_t b; //长按判断标志位
- volatile uint8_t openState=1,c=0;//灯效模式,默认关灯。单击openState = 0;双击openState = 1;长按openState = 2;
- volatile bool a=0,s=0; //刚刚结束滑动标志
- volatile uint8_t mind_n_As1; //
- uint64_t chipid;
- unsigned long startProducing, endProducing;
- volatile float mind_n_key1, mind_n_all, mind_n_oninall;
- // 函数声明
- void buttonACallback();
- void DF_C();
- void DF_B();
- void DF_onoff(uint16_t mind_n_on, uint16_t mind_n_off, uint8_t mind_n_key);
- void DF_A();
- void button_State()
- {
- //A
- if(!(digitalRead(button1))){ //检测按键是否按下
- delay(20); //延时去抖动
- if(!(digitalRead(button1))){//判断长短键
- while((!(digitalRead(button1)))&&(c
- c++;delay(10); //长按判断的计时
- // Serial.printf("A键按 %dn",c);//
- }
- if(c>=KEYA_SPEED1){ //长键处理 循环100次为长按1s
- //长按后执行的程序放到此处
-
- openState = 2;
-
- Serial.println("A键长按 rn");
- while(!(digitalRead(button1)));//等待按键松开
- }
- else{ //单击处理 按键A松开后
-
- if(a==0){
- for(b=0;b
- delay(20);
- if(!(digitalRead(button1))){//判断200ms内是否再次按下
- a=1;
- //双击后执行的程序放到此处
-
- openState = 1;
-
- Serial.println("A键双击 rn");
- }
- }
-
- if(a==0){ //判断单击
- if(s==1){ //判断是不是刚执行完滑动操作
- s=0; //如果是则本次不执行单击处理(因为是滑动的放开操作)
- }
- else{ //如果不是,则正常执行单击处理
- //单击后执行的程序放到此处
-
- openState = 0;
-
- Serial.println("A键单击 rn");
- }
- }
- }
- }
- a=0;c=0; //参数清0
- }
- } //按键判断在此结束
- }
- // 主程序开始
- void setup() {
- pinMode(OUT_PWM, OUTPUT);
- pinMode(LED_DT, OUTPUT);
- // pinMode(IN_0, INPUT);
- digitalWrite(OUT_PWM, LOW);//io14/d6
- // onEvent(ID_BUTTON_A, PRESS, buttonACallback);
- Serial.begin(115200);
- Serial.println("");
- delay(1000);
- pinMode(button1,INPUT_PULLUP);
- mind_n_key1 = 0;
- Serial.print("Setup: Executing on core ");
- Serial.println(xPortGetCoreID());
- chipid=ESP.getEfuseMac();//The chip ID is essentially its MAC address(length: 6 bytes).
- Serial.printf("ESP32 Chip ID = %04X",(uint16_t)(chipid>>32));//print High 2 bytes
- Serial.printf("%08Xn",(uint32_t)chipid);//print Low 4bytes.
-
- // Serial.printf("total heap size = %un",ESP.getHeapSize());
- Serial.printf("available heap = %un",ESP.getFreeHeap());
- // Serial.printf("lowest level of free heap since boot = %un",ESP.getMinFreeHeap());
- // Serial.printf("largest block of heap that can be allocated at once = %un",ESP.getMaxAllocHeap());
- // Serial.printf("total Psram size = %un",ESP.getPsramSize());
- // Serial.printf("available Psram = %un",ESP.getFreePsram());
- // Serial.printf("lowest level of free Psram since boot = %un",ESP.getMinFreePsram());
- // Serial.printf("largest block of Psram that can be allocated at once = %un",ESP.getMinFreePsram());
- Serial.printf("get Chip Revision = %un",ESP.getChipRevision());// uint8_t getChipRevision() 返回芯片版本号;
- Serial.printf("getCpuFreqMHz = %un",ESP.getCpuFreqMHz());// uint8_t getCpuFreqMHz() 返回芯片时钟频率;
- Serial.printf("get Cycle Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- Serial.printf("get SdkVersion = %sn",ESP.getSdkVersion());//const char * getSdkVersion() 返回SDK版本号;
- xTaskCreate(
- DF_A, /* Task function. */
- "DF_A", /* String with name of task. */
- 20000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
- xTaskCreate(
- buttonACallback, /* Task function. */
- "buttonA", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 3, /* Priority of the task. */
- NULL);
- }
- void loop() {
- delay(800);
- // Serial.print("Main Loop: Executing on core ");
- // Serial.println(xPortGetCoreID());
- // Serial.print("button1: ");
- // Serial.println((digitalRead(button1)));
- // Serial.print("LED_DT: ");
- // Serial.println((digitalRead(LED_DT)));
- // digitalWrite(LED_DT, HIGH); // turn the LED on (HIGH is the voltage level)
- // delay(1000); // wait for a second
- // digitalWrite(LED_DT, LOW); // turn the LED off by making the voltage LOW
- digitalWrite(LED_DT, 1 ^ digitalRead(LED_DT)); //翻转 输出电平
- }
- // 自定义函数
- void del_DF(const char* DFName) {
- pdTASK_CODE pvTask1;
- Serial.print("进入del_DF删除DF_ 程序:");
- Serial.println(DFName);
-
- if ((mind_n_key1==0)) {
-
- xTaskCreate(
- DF_A,
- "DF_A", /* String with name of task. */
- 20000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
- vTaskDelete( NULL ); //任务的删除
- }
- if ((mind_n_key1==1)) {
-
- xTaskCreate(
- DF_B,
- "DF_B", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
- vTaskDelete( NULL ); //任务的删除
- }
- if ((mind_n_key1==2)) {
-
- xTaskCreate(
- DF_C,
- "DF_C", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
- vTaskDelete( NULL ); //任务的删除
- }
- delay(60);
- Serial.print("删除DF_ ");
- Serial.println(DFName);
-
- }
- void DF_C(void * parameter) {
- Serial.print("Created task DF_c: Executing on core ");
- Serial.println(xPortGetCoreID());
- while (!(mind_n_key1<2)) {
- digitalWrite(OUT_PWM, LOW);
- delay(6);
- }
- if ((mind_n_key1==0)) {
-
- xTaskCreate(
- DF_A,
- "DF_A", /* String with name of task. */
- 20000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- if ((mind_n_key1==1)) {
-
- xTaskCreate(
- DF_B,
- "DF_B", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- Serial.println("删除DF_c");
- vTaskDelete( NULL ); //任务的删除
- }
- void DF_B(void * parameter) {
- uint16_t mind_a0_on;
- Serial.print("Created task DF_b: Executing on core ");
- Serial.println(xPortGetCoreID());
- while (mind_n_key1==1) {
- mind_a0_on=0;
- for(b=0;b<8;b++){//检测双击 循环10次200ms
- startProducing = ESP.getCycleCount();//开始时间
- mind_a0_on+=analogRead(IN_0);
- endProducing = ESP.getCycleCount();//结束时间
- Serial.print("mind_a0_on input A0 time all时间(CycleCount): ");
- Serial.println(( endProducing - startProducing));//写入耗费时间(CycleCount)
- Serial.printf("DF_b(analogRead(IN_0))%d: n",b);//
- Serial.println(analogRead(IN_0),mind_a0_on);
- }
-
- DF_onoff(mind_a0_on>>5, 1023, 1);
- }
- if ((mind_n_key1==0)) {
-
- xTaskCreate(
- DF_A,
- "DF_A", /* String with name of task. */
- 20000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- if ((mind_n_key1==2)) {
-
- xTaskCreate(
- DF_C,
- "DF_C", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- Serial.println("删除DF_b");
- vTaskDelete( NULL ); //任务的删除
-
- }
- void DF_onoff(uint16_t mind_n_on, uint16_t mind_n_off, uint8_t mind_n_key) {
- Serial.printf("DF_onoff Cycle Count mind_n_on:%d, uint16_t mind_n_off:%d, uint8_t mind_n_key:%dn",mind_n_on,mind_n_off, mind_n_key);//
- while ((mind_n_off>0)) {
- while ((mind_n_on>0)) {
- digitalWrite(OUT_PWM, HIGH);
- delay(6);
- mind_n_off -= 1;
- mind_n_on -= 1;
- if (!(mind_n_key==mind_n_key1)) {
- mind_n_off = 0;
- mind_n_on = 0;
- }
- }
- if ((mind_n_off>0)) {
- digitalWrite(OUT_PWM, LOW);
- delay(6);
- mind_n_off -= 1;
- if (!(mind_n_key==mind_n_key1)) {
- mind_n_off = 0;
- mind_n_on = 0;
- }
- }
- }
- }
- void DF_A(void * parameter) {
- uint8_t mind_n_Asn = 80;
- mind_n_As1 = 25;
- Serial.print("Created task DF_A: Executing on core ");
- Serial.println(xPortGetCoreID());
- startProducing = millis();//开始时间
- // Serial.printf("DF_A start Cycle Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- //Serial.println("");
- // Serial.printf(" millis %u start n",startProducing );//
- while (mind_n_As1>1) {
- DF_onoff(1023, 1023, 0);
- // Serial.printf("DF_A start Cycle Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- //Serial.println("");
- // Serial.printf(" millis: %u n",(millis()-startProducing ));//
- //Serial.println("");
- if ((mind_n_key1==0)) {
- // if (mind_n_As1 ==1) Serial.printf(" mind_n_As1: %u n",mind_n_As1);//
- mind_n_As1 -= 1;
- // if (mind_n_As1 ==0) Serial.printf(" mind_n_As1: %u n",mind_n_As1);//
- }
- else {
- del_DF("A");
- mind_n_As1 = 1;
- mind_n_Asn = 0;
- }
- // if (mind_n_As1 ==0) {Serial.printf(" goto mind_n_Aslabel: %u n",mind_n_As1);//
- // goto mind_n_Aslabel;
- // }
- // Serial.printf(" mind_n_As1: %u n",mind_n_As1);//
- //Serial.println("");
- }
- mind_n_Aslabel:
- Serial.printf("DF_A 50% start Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- Serial.println("");
- Serial.print("DF_A to 50% start Producing time 时间(ms): ");
- Serial.println(( millis() - startProducing));//写入耗费时间(ms)
- while (!(mind_n_Asn==0)) {
- DF_onoff(490, 1023, 0);
- if ((mind_n_key1==0)) {
- mind_n_Asn -= 1;
- }
- else {
- del_DF("A");
- // mind_n_As1 = 0;
- // mind_n_Asn = 0;
- }
- }
- // Serial.printf("DF_A end Count = %un",ESP.getCycleCount());// uint32_t getCycleCount() 返回自上电以来经过的时钟周期数(不太确定);
- //Serial.println("");
- endProducing = millis();//结束时间
- Serial.print("Producing time all时间(ms): ");
- Serial.println(( endProducing - startProducing));//写入耗费时间(ms)
- if ((mind_n_key1==0)) {
- mind_n_key1 = 2;
- }
- if ((mind_n_key1==1)) {
-
- xTaskCreate(
- DF_B,
- "DF_B", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- if ((mind_n_key1==2)) {
-
- xTaskCreate(
- DF_C,
- "DF_C", /* String with name of task. */
- 10000, /* Stack size in words. */
- NULL, /* Parameter passed as input of the task */
- 2, /* Priority of the task. */
- NULL);
-
- }
- Serial.println("删除DF_A");
- vTaskDelete( NULL ); //任务的删除
- }
- // 事件回调函数
- void buttonACallback(void * parameter) {
- Serial.print("Created task buttonA: Executing on core ");
- Serial.println(xPortGetCoreID());
- while(1){
- button_State();
- if ((openState==0)) {
- mind_n_key1 ++;
- openState=1;
- if ((mind_n_key1>2)) {
- mind_n_key1 = 0;
- }
- }
- delay(150);
- }
- }
复制代码
没有解决DF_A中出错。
0
|
1个回答
|
|
|