diff --git a/src/adc1256.cpp b/src/adc1256.cpp index f229c25..af79dd7 100644 --- a/src/adc1256.cpp +++ b/src/adc1256.cpp @@ -12,7 +12,7 @@ void adc1256_init(void) SPI.beginTransaction( SPISettings(clockMHZ * 1000000 / 4, MSBFIRST, SPI_MODE1)); sleep(0.5); - adc.begin(ADS1256_DRATE_30000SPS, ADS1256_GAIN_1, false); + adc.begin(ADS1256_DRATE_15SPS, ADS1256_GAIN_1, false); Serial.println("ADC Started"); diff --git a/src/main.cpp b/src/main.cpp index 08f691e..f2d8a6b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,8 +2,8 @@ #include "board.h" volatile bool task_adc1256_flag = false; -String read_val = ""; // 用于储存串口接收的字符串 -float array[5000]; // 存储数据 +String read_val = ""; // ڴ洮ڽյַ +float array[5000]; // 洢 int motor_home_step = 0; String fenge(String str, String fen, int index) { @@ -33,7 +33,7 @@ String fenge(String str, String fen, int index) void task_ads(void *pt) { - float array[1000]; // 存储数据 + float array[1000]; // 洢 uint16_t i = 0, j = 0; float temp = 0; @@ -47,13 +47,13 @@ void task_ads(void *pt) { motor_limit = MOTOR_LIMIT_OUTSIDE; - Serial.println("当前位置在限位器外,准备归位"); + Serial.println("ǰλλ⣬׼λ"); } else { motor_limit = MOTOR_LIMIT_WITHIN; motor_dir(-1); - Serial.println("当前位置在限位器内,准备归位"); + Serial.println("ǰλλڣ׼λ"); } motor_home_step = 0; motor_limit_on(); @@ -76,7 +76,7 @@ void task_ads(void *pt) } else { - Serial.println("开始读取ADC ..."); + Serial.println("ʼȡADC ..."); String part01 = fenge(read_val, ",", 0); String part02 = fenge(read_val, ",", 1); String part03 = fenge(read_val, ",", 2); @@ -84,42 +84,6 @@ void task_ads(void *pt) { adc1256_set_channel(3); Serial.printf("r,%.4f", adc1256_read()); - // if (part02 != "" && part03 != "") - // { - // int count = part02.toInt(); - // int delay = part03.toInt(); - // if (count < 1000) - // { - // memset(array, 0, sizeof(array)); - // for (i = 0; i < count; i++) - // { - // array[i] = adc1256_read(); - // vTaskDelay(delay); - // } - // // 对array[i]从小到大排序后取中间一个值 - // for (i = 0; i < count - 1; i++) - // { - // for (j = 0; j < count - 1 - i; j++) - // { - // if (array[j] > array[j + 1]) - // { - // temp = array[j]; - // array[j] = array[j + 1]; - // array[j + 1] = temp; - // } - // } - // } - // Serial.printf("r,%.4f", array[count / 2]); - // } - // else - // { - // Serial.println("Error: Invalid input"); - // } - // } - // else - // { - // Serial.println("Error: Invalid input"); - // } } } @@ -128,7 +92,7 @@ void task_ads(void *pt) task_adc1256_flag = false; break; } - vTaskDelay(100); // 延时100ms + vTaskDelay(100); // ʱ100ms } } @@ -140,7 +104,7 @@ void task_serial(void *pt) { while (Serial.available() > 0) { - read_val = read_val + char(Serial.read()); // 接收串口数据 + read_val = read_val + char(Serial.read()); // մ vTaskDelay(20); } if (read_val.length() > 0) @@ -158,7 +122,7 @@ void task_serial(void *pt) Serial.read(); } - vTaskDelay(100); // 延时100ms + vTaskDelay(100); // ʱ100ms } } @@ -181,7 +145,7 @@ void task_motor(void *pt) if (++motor_home_step == 12) { motor_limit_off(); - Serial.println("归位完成"); + Serial.println("λ"); } } @@ -190,7 +154,7 @@ void task_motor(void *pt) if (++motor_home_step == 6) { motor_limit_off(); - Serial.println("归位完成"); + Serial.println("λ"); } } }