RBE1001Lib
MotorMoveTo.ino
Go to the documentation of this file.
1 /*
2  * This program will wait for the button to be pressed and then command the left motor to
3  * spin one rotation at 120 rpm.
4  *
5  * While the motor is spinning, the program will print out how much it has turned (in degrees).
6  */
7 
8 #include <RBE1001Lib.h>
9 
12 
13 // pin definitions https://wpiroboticsengineering.github.io/RBE1001Lib/RBE1001Lib_8h.html#define-members
15 
16 /*
17  * This is the standard setup function that is called when the ESP32 is rebooted
18  * It is used to initialize anything that needs to be done once.
19  */
20 void setup()
21 {
22  // This will initialize the Serial as 115200 for prints
23  Serial.begin(115200);
24 
25  //explicitly make the button pin an input and engage the internal pullup resistor
26  pinMode(buttonPin, INPUT_PULLUP);
27 }
28 
29 /*
30  * The main loop for the program. The loop function is repeatedly called
31  * once the ESP32 is started.
32  */
33 void loop()
34 {
35  //The following line will cause the program to wait indefinitely until the button is pressed
36  //It'll print out motor data while it waits
37  while (digitalRead(buttonPin))
38  {
39  Serial.print(motor_left.getCurrentDegrees()); //motor1 position
40  Serial.print('\t'); //TAB character
41  Serial.print(motor_right.getCurrentDegrees()); //motor2 position
42  Serial.print('\n'); //newline character
43  }
44 
45  motor_left.moveTo(360, 120); //spin once at 120 degrees per second
46 
47  Serial.print(motor_left.getCurrentDegrees()); //motor1 position
48  Serial.print('\t'); //TAB character
49  Serial.print(motor_right.getCurrentDegrees()); //motor2 position
50  Serial.print('\n'); //newline character
51 
52  delay(50);
53 }
void loop()
Definition: MotorMoveTo.ino:33
const int buttonPin
Definition: MotorMoveTo.ino:14
#define BOOT_FLAG_PIN
Definition: RBE1001Lib.h:12
LeftMotor motor_left
Definition: MotorMoveTo.ino:10
float getCurrentDegrees()
Definition: Motor.cpp:568
void moveTo(float newTargetInDegrees, float speedDegPerSec)
Definition: Motor.cpp:182
void setup()
Definition: MotorMoveTo.ino:20
RightMotor motor_right
Definition: MotorMoveTo.ino:11