Kinetic Sculpture
3.1
Software to Architecture for the Junior Kinetic Sculpture Project
|
#include <Motor.h>
Public Member Functions | |
Motor (byte direction, byte pwm, byte tachPin) | |
void | setupMotor () |
void | runMotor (double percent) |
double | turnPercentIntoPwm (double percent) |
void | turnOffMotor () |
void | turnOnMotor () |
void | increasePercentage (double step) |
void | decreasePercentage (double step) |
void | interruptServiceRoutine () |
unsigned long | getRotationsPerMinute () |
byte | getTachAttachedPin () |
double | getPercentage () |
double | getDirection () |
bool | setMinimumUsablePercent (byte percent) |
byte | getMinUsablePercent () |
byte | getMaxUsablePercent () |
bool | setMaxUsablePercent (byte percent) |
Public Attributes | |
const byte | FULL_OFF = 255 |
const byte | FULL_ON = 0 |
double | percentage = 0 |
Class to interact with each motor on the PCB The motor class also includes tachometer support which is used to get the RPM that the motor is running at
Written by Wade Varesio and Courtney McIntosh 05/13/2019
|
inline |
Constructor to create a Motor object
direction | - pin number that controls the direction of the motor |
pwm | - pin number that the motor PWM pin is on. (Hint: Pulse Width Modulation AKA PWM is how you dim LEDs and control the motor) |
tachPin | - pin number that the tachometer is attached to on the Arduino |
|
inline |
Sets up Motor to spin.
Sets pinNumber and directionPin to be an OUTPUT, tachometer pin to be an input.
|
inline |
Runs a motor at a given speed in percent
Makes the disc spin clockwise if percent is positive, and counterclockwise if it is negative. Calls the turnOnMotor function at a given percent.
percent | - the percent at which you want to run the motor. |
|
inline |
Takes a percentage in the form of a double and turns it into a PWM signal for motor control.
A percentage value of 0 is off (returns a PWM value of 255), and 100 is fully on (returns a PWM value of 0).
percent | - the percentage value to be converted to a PWM value. |
|
inline |
Turn the motor completely off
|
inline |
Turn the motor completely on
|
inline |
Increases percentage the motor is running at
Calls the runMotor function at this new percentage.
step | - the amount you want the percentage to increase by. |
|
inline |
Decreases percentage
Subtracts .25 from the value of percentage. Calls the runMotor function at this new percentage.
step | - the amount you want the percentage to increase by. |
|
inline |
Interrupt service routine for the Tachometer
ISR for when the pin falls low, this is necessary to get a measurement and convert into the RPM of the motor.
|
inline |
|
inline |
|
inline |
Get the motors current percentage
|
inline |
Get the direction that the motor is spinning in
|
inline |
Set the minimum percentage required to run a motor. This should ONLY be called if your motor requires a higher minimum than the normal 40%.
percent | new minimum motor percentage. Must be less than 100 and non negative or the request will be ignored. |
|
inline |
Get the minimum usable percent the motor is able to run at
|
inline |
Get the maximum usable percent of power the motor is able to run at
|
inline |
Set the maximum usable percentage the motor will run at. This should only be called when a motor requires a special maximum power limit
percent | the new maximum percentage a motor is allowed to run at. Percent must be greater than minUsablePercent (defaults to 40) and less or equal to 100. |
const byte Motor::FULL_OFF = 255 |
The signal is inverted therefore FULL_OFF is 255
const byte Motor::FULL_ON = 0 |
The signal is inverted therefore FULL_ON is 0
double Motor::percentage = 0 |
The percentage of power that the motor is running at