Advertisement
AngyalRobert

measureMSec

Jun 20th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1.  
  2. #define inputPin 3
  3. unsigned long mSec;
  4. unsigned long oldMillis;
  5. unsigned char oldInput;
  6.  
  7. void setup() {
  8.   // put your setup code here, to run once:
  9.   pinMode( inputPin, INPUT_PULLUP);
  10.   Serial.begin(115200);
  11.   oldMillis= millis();
  12.   oldInput= digitalRead( inputPin);
  13. }
  14.  
  15. void loop() {
  16.   // put your main code here, to run repeatedly:
  17.  
  18.   unsigned char inputNow= digitalRead( inputPin);
  19.   if (oldInput!= inputNow) {
  20.     unsigned long millisNow= millis();
  21.     mSec= millisNow- oldMillis;
  22.     oldMillis= millisNow;
  23.     oldInput= inputNow;
  24.     Serial.print( mSec);
  25.     Serial.write( "\n");
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement