Motor Shield V2.0 DC motor

Hello I’m trying to drive a DC motor forward and backwards as well as control the speed. I’ll be controlling it with 3 switches. So far I think I’ve written the code for it as it should but have run into problems while trying it out.

It seems while the motor would spin forward and backward at full speed and at lower speeds using the DCMotorDemo the same was not the case when I tried out my code. I have power going to UNO and power going to the shield.

I’m pretty new to all of this so any help would be greatly appreciated.


#include <MotorDriver.h>

int Yellow = 7;
int Green = 6;
int White = 5;

void setup()
{
pinMode(Yellow,INPUT);
pinMode(Green, INPUT);
pinMode(White, INPUT);
motordriver.init();
}

void loop ()


{
 if(digitalRead(Yellow)==LOW)
 {
   motordriver.stop();
   motordriver.setSpeed(255,MOTORB);
   motordriver.goForward();

 }
 else
 {
 
   motordriver.stop();
 }
 {
   if(digitalRead(Green)==LOW && digitalRead(Yellow)==LOW)
   {
     motordriver.stop();
     motordriver.setSpeed(100,MOTORB);
     motordriver.goForward();
   }
   else
   {
     motordriver.stop();
   }
   if(digitalRead(Green)==LOW && digitalRead(White)==LOW)
   {
    motordriver.stop ();
    motordriver.setSpeed(100, MOTORB);
    motordriver.goBackward();
   }
if(digitalRead(White)==LOW)
{
  motordriver.stop();
  motordriver.setSpeed(255,MOTORB);
  motordriver.goBackward();
  
}
else
{
  motordriver.stop();
}

 }}