Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct WheelStruct {
- int mspeed; // Max is 255
- boolean mForward; // Is going forward or not.
- const int speedPinD; // Digital, PWM
- const int directionPinD; // Digital
- const int brakePinD; // Digital (I've got no clue what this is.)
- const int currentSensingPinA; // Analog
- };
- const int ZERO = 0;
- const int MAX = 255;
- const int HALF = 128;
- const int QUARTER = 64;
- WheelStruct motorA = {
- ZERO, true, 3, 12, 9, 0}; // Motor A is left
- WheelStruct motorB = {
- ZERO, true, 11, 13, 8, 1}; // Motor B is right.
- const int ledLampAPin = 4;
- const int ledLampBPin = 5;
- /* PROTOTYPE STARTS HERE */
- void switchWheelDirection(int);
- void writeMotor(int, int);
- void forward(int);
- void motorTurn(int, int);
- void spinAround(boolean);
- /* PROTOTYPE ENDS HERE */
- void setup(){
- pinMode(motorA.speedPinD, OUTPUT);
- pinMode(motorB.speedPinD, OUTPUT);
- pinMode(motorA.directionPinD, OUTPUT);
- pinMode(motorB.directionPinD, OUTPUT);
- pinMode(motorA.brakePinD, OUTPUT);
- pinMode(motorB.brakePinD, OUTPUT);
- pinMode(motorA.currentSensingPinA, INPUT);
- pinMode(motorB.currentSensingPinA, INPUT);
- }
- void loop(){
- forward(255);
- }
- /* FUNCTIONS STARTS HERE */
- /* *
- * switchWheelDirection - toggles the state of mDirPin (Motor Direction Pin) *
- * */
- void switchWheelDirection(int mDirPin){
- }
- /* *
- * writeMotor - replaces the analogWrite() function, positive values = forward *
- * negative values = backwards, for ex "mspeed = 100" == motorX.mspeed == 100 *
- * */
- void writeMotor(int pin, int mspeed){
- if (mspeed >= 0 || mspeed < 255){
- analogWrite(pin, mspeed); // Will be writeMotor
- }
- else if(mspeed >= -255 && mspeed <= 0){
- // Switch to backwards and
- analogWrite(pin, abs(mspeed)); // Will be writeMotor
- }
- }
- /* *
- *forward - changes the state of motor A & B to forward & sets motorX.mspeed to fspeed*
- * */
- void forward(int fspeed){
- digitalWrite(motorA.directionPinD, HIGH);
- digitalWrite(motorB.directionPinD, HIGH);
- analogWrite(motorA.speedPinD, fspeed); // Will be writeMotor
- analogWrite(motorB.speedPinD, fspeed); // -||-
- }
- /* *
- * motorTurn - change the speed of each wheel idividually. *
- * */
- void motorTurn(int lSpeed, int rSpeed){
- analogWrite(motorA.speedPinD, lSpeed); // Will be writeMotor
- analogWrite(motorB.speedPinD, rSpeed); // Will be writeMotor
- }
- /* *
- * spinAround - spins the car clockwise/anti-clockwise depending on bool clockwise *
- * use forward or brake to disable. *
- * */
- void spinAround(boolean clockwise){
- if(clockwise == true){
- // Makes the other wheel go forward, the other one backward.
- }
- }
- /* *
- * brake - stops all motors and sets their mspeed at 0 *
- * */
- void brake(){
- digitalWrite(motorA.brakePinD, HIGH);
- digitalWrite(motorA.brakePinD, HIGH);
- analogWrite(motorA.speedPinD, ZERO);
- analogWrite(motorB.speedPinD, ZERO);
- }
- /* FUNCTIONS ENDS HERE */
Advertisement
Add Comment
Please, Sign In to add comment