Advertisement
ossipee

groamer2

Aug 20th, 2014
305
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.  terry@yourduino.com */
  4.  
  5. /*-----( Declare Constants )-----*/
  6. #define SWITCHPIN 3
  7. #define LEDPIN    13  // The onboard LED
  8.  
  9. /*-----( Declare Variables )-----*/
  10. int  switch_state;  /* Holds the last state of the switch */
  11.  
  12. void setup()   /*----( SETUP: RUNS ONCE )----*/
  13. {
  14.   pinMode(LEDPIN, OUTPUT);
  15.  
  16. }/*--(end setup )---*/
  17.  
  18.  
  19. void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
  20.  
  21. // This module is ACTIVE LOW when a reflection is seen
  22. {
  23.  
  24.   switch_state = digitalRead(SWITCHPIN);  
  25.   if (switch_state == LOW)
  26.   {
  27.     digitalWrite(LEDPIN, HIGH);
  28.   }  
  29.   else
  30.   {
  31.     digitalWrite(LEDPIN, LOW);
  32.   }
  33. }/* --(end main loop )-- */
  34.  
  35. /* ( THE END ) */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement