Advertisement
ossipee

groamer2

Aug 20th, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. /* YourDuino Electronic Brick Test:
  2.  Single Track Reflective Sensor AB-010201
  3.  
  4. /*-----( Declare Constants )-----*/
  5. #define SWITCHPIN 3
  6. #define LEDPIN    13  // The onboard LED
  7.  
  8. /*-----( Declare Variables )-----*/
  9. int  switch_state;  /* Holds the last state of the switch */
  10.  
  11. void setup()   /*----( SETUP: RUNS ONCE )----*/
  12. {
  13.   pinMode(LEDPIN, OUTPUT);
  14.  
  15. }/*--(end setup )---*/
  16.  
  17.  
  18. void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
  19.  
  20. // This module is ACTIVE LOW when a reflection is seen
  21. {
  22.  
  23.   switch_state = digitalRead(SWITCHPIN);  
  24.   if (switch_state == LOW)
  25.   {
  26.     digitalWrite(LEDPIN, HIGH);
  27.   }  
  28.   else
  29.   {
  30.     digitalWrite(LEDPIN, LOW);
  31.   }
  32. }/* --(end main loop )-- */
  33.  
  34. /* ( THE END ) */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement