Advertisement
LordSydney

Adrino: Photoresistor

Apr 20th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1.  
  2. // 4 pins of the stepper motor board
  3. #define _PIN1 8
  4. #define _PIN2 9
  5. #define _PIN3 10
  6. #define _PIN4 11
  7.  
  8. // Interruption on PIN2
  9. #define ITR_PIN 2
  10.  
  11.  
  12. volatile int count = 0;
  13. volatile int triggers = 0;
  14. volatile int lastTrigger = 0;
  15.  
  16. const unsigned int BAUD_RATE = 9600;
  17.  
  18. void Trigger()
  19. {
  20. triggers++;
  21. }
  22.  
  23.  
  24. void setup()
  25. {
  26. cli();
  27. pinMode(ITR_PIN, INPUT_PULLUP);
  28. attachInterrupt(0, Trigger, FALLING);
  29. sei();
  30.  
  31. Serial.begin(BAUD_RATE);
  32. Serial.println("Go");
  33. Serial.flush();
  34. }
  35.  
  36.  
  37. void loop()
  38. {
  39. if (triggers != lastTrigger)
  40. {
  41. // Debounce count
  42. lastTrigger = triggers;
  43. count++;
  44.  
  45. // Output count
  46. Serial.println(count);
  47. Serial.flush();
  48. }
  49. delay(200);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement