-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
56 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// include the library for the encoder | ||
#include <Encoder.h> | ||
|
||
// define the pins for the encoder | ||
#define ENC_A 2 | ||
#define ENC_B 15 | ||
|
||
// create an Encoder object | ||
Encoder myEnc(ENC_A, ENC_B); | ||
|
||
// define the pins for the motor control | ||
#define MOTOR_1 26 | ||
#define MOTOR_2 25 | ||
|
||
// define the target count | ||
#define TARGET_COUNT 370 | ||
|
||
void setup() { | ||
// set the motor control pins as outputs | ||
pinMode(MOTOR_1, OUTPUT); | ||
pinMode(MOTOR_2, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
// read the encoder count | ||
long count = myEnc.read(); | ||
|
||
// check if the target count has been reached | ||
if (count < TARGET_COUNT) { | ||
// set the motor speed and direction | ||
digitalWrite(MOTOR_1, HIGH); | ||
digitalWrite(MOTOR_2, LOW); | ||
} else { | ||
// stop the motor | ||
digitalWrite(MOTOR_1, LOW); | ||
digitalWrite(MOTOR_2, LOW); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters