Project number ten does not work


okay, have tried literally make tis project work, when press button makes motor spin, nothing happens. have assembled circuit bunch of times nothing seems happened , went store , new replacement of h bridge, because thought may solution, nothing happened. program told me codes right, anyways here leave them , hope can me this.


const int controlpin1 = 2;
const int controlpin2 = 3;
const int enablepin = 9;
const int directionswitchpin = 4;
const int onoffswitchstateswitchpin = 5;
const int potpin = a0;

int onoffswitchstate = 0;
int previousonoffswitchstate = 0;
int directionswitchstate = 0;
int previousdirectionswitchstate = 0;

int motorenabled = 0;
int motorspeed = 0;
int motordirection = 1;

void setup() {
  // put setup code here, run once:
  pinmode(directionswitchpin, input);
  pinmode(onoffswitchstateswitchpin, input);
  pinmode(controlpin1, output);
  pinmode(controlpin2, output);
  pinmode(enablepin, output);
  digitalwrite(enablepin, low);
}

void loop() {
  // put main code here, run repeatedly:
  onoffswitchstate =
     digitalread(onoffswitchstateswitchpin);
  delay(1);
  directionswitchstate =
     digitalread(directionswitchpin);
  motorspeed = analogread(potpin)/4;
  if(onoffswitchstate != previousonoffswitchstate){
    if(onoffswitchstate == high){
      motorenabled = !motorenabled;
    }
  }
  if (directionswitchstate !=
  previousdirectionswitchstate) {
  if (directionswitchstate == high) {
    motordirection = !motordirection;
   }
  }
  if (motordirection == 1) {
    digitalwrite(controlpin1, high);
    digitalwrite(controlpin2, low);
  }

  else {
    digitalwrite(controlpin1, low);
    digitalwrite(controlpin2, high);
  }
  if (motorenabled == 1) {
    analogwrite(enablepin, motorspeed);
  }
  else {
    analogwrite(enablepin, 0);
  }
  previousdirectionswitchstate =
    directionswitchstate;
  previousonoffswitchstate = onoffswitchstate;
}

please read post @ top of each section 'how use forum - please read'. contains information assist in getting best responses people trying you.

anyway, if confident code correct there must error in way have connected together. code available in ide - file -> examples -> 10. starter kit.



Arduino Forum > Products > The Arduino Starter Kit and Basic Kit > Project number ten does not work


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???