Advertisement
Guest User

claw button

a guest
Feb 9th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1.  //global
  2. unsigned short pos = 0;
  3.  
  4. //in loop
  5. if(digitalRead(btnClawIncrementPin))
  6. {
  7.     pos += ((pos == 180) ? 0 : 1); //I love the ternary operator. No forking here!
  8.     clawServo.write(pos);
  9. }
  10. else if(digitalRead(btnClawDecrementPin))
  11. {
  12.     pos -= ((pos == 0) ? 0 : 1);
  13.     clawServo.write(pos);
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement