-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
65 lines (47 loc) · 1.28 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//Basic Libraries
#include <Arduino.h>
#include <Servo.h>
#include <math.h>
//Define Servo
Servo myServo;
//Define Randomness Function
long pick;
//Define Button ports & button states
const int button = 2;
int buttonState = 0;
//Define Math Variables
void setup() {
//Define Servo Port
myServo.attach(3);
//Define the button's pin mode
pinMode(button, INPUT_PULLUP);
//Port that the rng runs off of
randomSeed(analogRead(0));
//Define how button works
buttonState = digitalRead(button);
//Sets the servo arm to the middle of the spectrum
myServo.write(90);
}
void loop() {
//Define how button works (again)
buttonState = digitalRead(button);
//If the button is pressed then it will pick a random number between
//One and 500 and will check if it is even. If it is then it will
//rotate to the right, if it is not even then it will rotate to the left.
//After that is done then it will reset to the original position and wait for
//the button to be pressed again.
if (buttonState == HIGH){
delay(250);
pick = random(1, 501);
if (( pick % 2) == 0 )
{
myServo.write(180);
}
else{
myServo.write(0);
}
delay(5000);
myServo.write(90);
delay(5000);
}
}