Nike622000

Stoppino

Feb 20th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. volatile bool rs = false;
  2. volatile unsigned long ti[4] = {0,0,0,0};  
  3.  
  4. int _7SEG[] = {B00111111, B00000110, B01011011, B01001111,   //0 1 2 3
  5.                B01100110, B01101101, B01111101, B00000111,   //4 5 6 7
  6.                B01111111, B01101111, B00000000};              //8 9 /
  7.  
  8. void printNum();
  9.  
  10. void setup(){
  11.   Serial.begin(9600);
  12.   for(byte i = 0; i <= 1; i++)
  13.     pinMode(18+i, INPUT);
  14.   for(byte i = 0; i <= 19; i++)
  15.     pinMode(22+i, OUTPUT);
  16.  
  17.   pinMode(2, INPUT);
  18.   attachInterrupt(digitalPinToInterrupt(2), timestamp, CHANGE);
  19.   attachInterrupt(digitalPinToInterrupt(18), rsInt, RISING);
  20. }
  21.  
  22. void loop(){  
  23.   if(ti[3]){
  24.     Serial.println(ti[3]);
  25.   }
  26. }
  27.  
  28. void timestamp(){
  29.   volatile byte i = 0;
  30.   while(ti[i] && i <= 3)
  31.     i++;
  32.    
  33.   if(i <= 3)
  34.     ti[i] = micros();
  35. }
  36.  
  37. void rsInt(){
  38.   ti[0] = 0;
  39.   ti[1] = 0;
  40.   ti[2] = 0;
  41.   ti[3] = 0;
  42. }
  43.  
  44. /*void printNum(unsigned long num){
  45.   for(byte i = 0; i <= 6; i++){
  46.     for(byte j = 0; j <= 7; j++)
  47.       digitalWrite(22+j, bitRead(_7SEG[num%10],j));
  48.     num = num/10;
  49.    
  50.     digitalWrite(36-i, HIGH);
  51.     delay(1);
  52.     digitalWrite(36-i, LOW);
  53.   }
  54. }*/
Advertisement
Add Comment
Please, Sign In to add comment