本帖最后由 凯风自北来 于 2015-8-4 18:51 编辑
- #include <Keypad.h>
- float flowrate = 1000;
- float diameter = 8.24;
- float area;
- float velocity;
- char customKey;
- const byte ROWS = 4; //four rows
- const byte COLS = 4; //four columns
- char hexaKeys[ROWS][COLS] = {
- {'1','2','3','A'},
- {'4','5','6','B'},
- {'7','8','9','C'},
- {'*','0','#','D'}
- };
- byte rowPins[ROWS] = {9, 8, 7, 6};
- byte colPins[COLS] = {5, 4, 3, 2};
- Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
-
- void setup() {
- Serial.begin(9600);
-
- }
- void loop()
- {
- if(customKeypad.getKey() !=NO_KEY)
- { sysConfig();
- area=3.14*pow((diameter/2),2);
- velocity=(flowrate/area)*20/3;
- Serial.print("velocity = ");
- Serial.print(velocity);
- Serial.println(" steps/s");}
- }
-
- void sysConfig(){
- String res="";
- String data[4]="";
- while( customKeypad.getKey() !='#')
- {
- customKey = customKeypad.getKey();
- res += char(customKey);delay(100);
- }
- Serial.println("Input: ");
- Serial.println(res);
- Serial.println("----------------------");
- Serial.println("Output: ");
- for(int i=0,j=0,l=res.length();i<l;i++){
- if(res[i] == '*') j++;
- else data[j] += char(res[i]);
- if(j > 3) break;
- }
- if(data[0]=="A"){
- flowrate= atof(data[1].c_str());
- Serial.print( "flowrate = ");
- Serial.print(flowrate);
- Serial.println(" uL/min ");
- }
-
- if(data[2]=="B"){
- diameter= atof(data[3].c_str());
- Serial.print( "diameter = ");
- Serial.print( diameter);
- Serial.println(" mm ");
- }
- else{
- Serial.println("Unknown command");
- }
- Serial.println("----------------------");
- }
复制代码
输入A*1000*B*10#后显示如下,请问是哪里出错了
|