SHARE
TWEET

Untitled

a guest Jun 25th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Servo.h>
  2.  
  3. Servo SERVO;
  4. long math_random_int(int a,int b) {
  5.   if (a > b) {
  6.     // Swap a and b to ensure a is smaller.
  7.     int c = a;
  8.     a = b;
  9.     b = c;
  10.   }
  11.   return random(a,b);
  12. }
  13.  
  14. int randAngle;
  15.  
  16. void setup() {
  17.   SERVO.attach(9);
  18.   pinMode(2, INPUT);
  19.     pinMode(2, INPUT_PULLUP);
  20.   randAngle = 45;
  21.  
  22. }
  23.  
  24. void loop() {
  25.     if (digitalRead(2) == LOW) {
  26.       SERVO.write(randAngle);
  27.  
  28.     } else {
  29.       randAngle = math_random_int(0, 180);
  30.  
  31.     }
  32.  
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top