Kinetic Sculpture  3.1
Software to Architecture for the Junior Kinetic Sculpture Project
 All Classes Files Functions Variables Macros Pages
Public Member Functions | Public Attributes | List of all members
Motor Class Reference

#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
 

Detailed Description

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

Constructor & Destructor Documentation

Motor::Motor ( byte  direction,
byte  pwm,
byte  tachPin 
)
inline

Constructor to create a Motor object

Parameters
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

Member Function Documentation

void Motor::setupMotor ( )
inline

Sets up Motor to spin.

Sets pinNumber and directionPin to be an OUTPUT, tachometer pin to be an input.

void Motor::runMotor ( double  percent)
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.

Parameters
percent- the percent at which you want to run the motor.
double Motor::turnPercentIntoPwm ( double  percent)
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).

Parameters
percent- the percentage value to be converted to a PWM value.
Returns
returns the conversion of the percent in a PWM value
void Motor::turnOffMotor ( )
inline

Turn the motor completely off

void Motor::turnOnMotor ( )
inline

Turn the motor completely on

void Motor::increasePercentage ( double  step)
inline

Increases percentage the motor is running at

Calls the runMotor function at this new percentage.

Parameters
step- the amount you want the percentage to increase by.
void Motor::decreasePercentage ( double  step)
inline

Decreases percentage

Subtracts .25 from the value of percentage. Calls the runMotor function at this new percentage.

Parameters
step- the amount you want the percentage to increase by.
void Motor::interruptServiceRoutine ( )
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.

unsigned long Motor::getRotationsPerMinute ( )
inline
Returns
the motors current rotations per minute
byte Motor::getTachAttachedPin ( )
inline
Returns
the attached Tachometer pin
double Motor::getPercentage ( )
inline

Get the motors current percentage

Returns
percentage the motor is running at
double Motor::getDirection ( )
inline

Get the direction that the motor is spinning in

Returns
the direction that the motor is spinning in 1 clockwise, 0 counterclockwise
bool Motor::setMinimumUsablePercent ( byte  percent)
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%.

Parameters
percentnew minimum motor percentage. Must be less than 100 and non negative or the request will be ignored.
Returns
true if percent is valid and the min usable percentage was set, false otherwise
byte Motor::getMinUsablePercent ( )
inline

Get the minimum usable percent the motor is able to run at

Returns
the current minimum percentage of power required to run a motor
byte Motor::getMaxUsablePercent ( )
inline

Get the maximum usable percent of power the motor is able to run at

Returns
Max percent of power the motor is able to run at
bool Motor::setMaxUsablePercent ( byte  percent)
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

Parameters
percentthe 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.
Returns
true if percent is valid and the motors max usable percent was set, false otherwise

Member Data Documentation

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


The documentation for this class was generated from the following file: