- unsigned int Speed = 0;
- int IRsensor = 2;
- void setup()
- {
- Serial.begin(9600);
- Serial.println("Start!");
- pinMode(IRsensor,INPUT);
-
- }
-
- void loop(){
- static unsigned long timepoint = millis();
- static unsigned long timepoint1 = millis();
- static byte count = 0;
-
- if(millis()-timepoint > 2)
- {
- timepoint = millis();
- if(digitalRead(IRsensor)) count = 0;
- if( (count<30) && (++count==10) )
- Speed++;
- }
-
- if(millis()-timepoint1 > 10000){
- timepoint1 = millis();
- Speed = Speed * 6;
- Serial.print("Speed is: ");
- Serial.println(Speed);
- Speed = 0;
- }
-
- }
-
复制代码
|