Advertisement
patryk

Untitled

Mar 26th, 2015
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. int s0=3,s1=4,s2=5,s3=6;
  2. int out=2;
  3. int flag=0;
  4. byte counter=0;
  5. byte countR=0,countG=0,countB=0;
  6. void setup()
  7.  {
  8.  Serial.begin(115200);
  9.  pinMode(s0,OUTPUT);
  10.  pinMode(s1,OUTPUT);
  11.  pinMode(s2,OUTPUT);
  12.  pinMode(s3,OUTPUT);
  13.  
  14.  }
  15. void TCS()
  16.  {
  17.  flag=0;
  18.  digitalWrite(s1,HIGH);
  19.  digitalWrite(s0,HIGH);
  20.  digitalWrite(s2,LOW);
  21.  digitalWrite(s3,LOW);
  22.  attachInterrupt(0, ISR_INTO, LOW);
  23.  timer0_init();
  24.  
  25.  }
  26. void ISR_INTO()
  27.  {
  28.  counter++;
  29.  }
  30.  void timer0_init(void)
  31.  {
  32.   TCCR2A=0x00;
  33.   TCCR2B=0x07;   //the clock frequency source 1024 points
  34.   TCNT2= 100;    //10 ms overflow again
  35.   TIMSK2 = 0x01; //allow interrupt
  36.  }
  37.  int i=0;
  38.  ISR(TIMER2_OVF_vect)//the timer 2, 10ms interrupt overflow again. Internal overflow interrupt executive function
  39. {
  40.     TCNT2=100;
  41.     flag++;
  42.  if(flag==1)
  43.   {
  44.     countR=counter;
  45.     Serial.print("red=");
  46.     Serial.println(countR,DEC);
  47.     digitalWrite(s2,HIGH);
  48.     digitalWrite(s3,HIGH);
  49.   }
  50.   else if(flag==2)
  51.    {
  52.     countG=counter;
  53.     Serial.print("green=");
  54.     Serial.println(countG,DEC);
  55.     digitalWrite(s2,LOW);
  56.     digitalWrite(s3,HIGH);
  57.    }
  58.    else if(flag==3)
  59.     {
  60.     countB=counter;
  61.     Serial.print("blue=");
  62.     Serial.println(countB,DEC);
  63.     Serial.println("\n");
  64.     digitalWrite(s2,LOW);
  65.     digitalWrite(s3,LOW);
  66.  
  67.     }
  68.     else if(flag==4)
  69.      {
  70.      flag=0;
  71.      }
  72.        counter=0;
  73. }
  74. void loop()
  75.  {
  76.   TCS();
  77. while(1);
  78.  
  79.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement