-
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
1 parent
7900c9c
commit c2b326f
Showing
8 changed files
with
91 additions
and
13 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,22 @@ | ||
#include "Stepper.h" | ||
#include <unistd.h> | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
// create an instance of the stepper class with suitable pins set up | ||
Stepper stepper(8, 10, 9, 11); | ||
|
||
// configure the stepper motor speed in RPM | ||
stepper.setSpeed(10); | ||
|
||
// move the motor the number of steps indicated by val | ||
uint8_t val = 42; | ||
stepper.move_clockwise(val); | ||
|
||
// wait for the stepper motor to finish moving | ||
while(stepper.isRunning()) { | ||
sleep(1); | ||
} | ||
|
||
} | ||
|
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
set(SRC_LIB_NAME src) | ||
set(SOURCES sample.cpp) | ||
set(SOURCES | ||
Stepper.cpp | ||
Stepper.h) | ||
add_library(${SRC_LIB_NAME} ${SOURCES}) | ||
target_sources(${SRC_LIB_NAME} PRIVATE ${SOURCES}) | ||
target_include_directories(${SRC_LIB_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) |
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,22 @@ | ||
|
||
|
||
#include "Stepper.h" | ||
|
||
void Stepper::setSpeed(uint8_t speed) { | ||
_speed = speed; | ||
} | ||
|
||
void Stepper::move_clockwise(uint8_t steps) { | ||
// logic to activate the relevant pins is omitted in this exercise | ||
} | ||
|
||
void Stepper::move_anticlockwise(uint8_t steps) { | ||
// logic to activate the relevant pins is omitted in this exercise | ||
} | ||
|
||
bool Stepper::isRunning() { | ||
// logic to read the pins and determine this omitted in this exercise | ||
return false; | ||
} | ||
|
||
|
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,42 @@ | ||
#ifndef STEPPER_H | ||
#define STEPPER_H | ||
|
||
#include <cstdint> | ||
|
||
// the number of steps to rotate a complete circle of 360 degrees | ||
#define STEPS 2048 | ||
|
||
// the maximum speed of the motor in RPM | ||
#define MAX_SPEED = 15 | ||
|
||
/* | ||
* This class is a placeholder for a real object that would be able to | ||
* control an electric stepper motor. | ||
*/ | ||
class Stepper { | ||
public: | ||
explicit Stepper( | ||
const uint8_t pin1 = 8, | ||
const uint8_t pin2 = 9, | ||
const uint8_t pin3 = 10, | ||
const uint8_t pin4 = 11): _speed(10) { | ||
}; | ||
|
||
// Set the speed of the motor in RPM. Maximum is defined above. | ||
void setSpeed(uint8_t); | ||
|
||
// Move the indicated number of steps. The size of a step is defined above. | ||
void move_clockwise(uint8_t steps); | ||
|
||
void move_anticlockwise(uint8_t steps); | ||
|
||
// Whether the motor is currently moving. | ||
// Motors that are moving should not be given new instructions. | ||
bool isRunning(); | ||
|
||
private: | ||
int _speed; | ||
}; | ||
|
||
|
||
#endif //STEPPER_H |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include "sample.h" | ||
|
||
using namespace std; | ||
|
||
TEST(SampleSuite, SampleTest) { | ||
|