1程序例子1
void setup() {
Serial.begin(9600);
}
void loop() {
while (Serial.available() > 0)
{
char i = Serial.read();
int ser = Serial.parseInt();
switch(i)
{
case 'T':
measureCurrentInTime( ser);
break;
case 'C':
measureCurrentInCiShu(ser);
delay(15);
break;
}
}
}
void measureCurrentInTime(int ser){
for(;;){
Serial.println("测试中。。。");
Serial.print ("时间");
Serial.println(ser);
delay(1000); ser++;
if(Serial.read()=='S') break;
}
}
void measureCurrentInCiShu(int ser){
for(;;){
Serial.println("测试中。。。");
Serial.print("次数");
Serial.println(ser);
ser++;
delay(1000);
if(Serial.read()=='S') break;
}
}
2程序例子2
String comdata = "";
void setup()
{
Serial.begin(9600);
}
void loop()
{
while (Serial.available() > 0){
comdata += char(Serial.read());
delay(2);
for(int i=0;i<comdata.length();i++){
Serial.println(comdata[i]);
delay(1000);
}
}
}