0

DC Motor not turning help

https://www.tinkercad.com/things/e0qiREMIrxj-copy-of-encoder-interrupt-pulse-counting/editel?sharecode=FJQCXA0pQcUzpeLRLYd_2acCCxtC7N6CNPSN_1bxiKA

Why does the motor not turn in this code?  If I change the if statement as per the comment in the code it turns?

 

Thanks

unsigned int encoder_ticks=0;
int serialInstruction;

void setup()
{
pinMode(5, OUTPUT);
pinMode(6,OUTPUT);
pinMode(2,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);
Serial.begin(9600);

attachInterrupt(0,encoderA,RISING);
}

void loop()
{
Serial.println((String)
"serialInstruction: " + serialInstruction);
if (Serial.available()) {
serialInstruction = Serial.read();
}

// only start moving the motor after "a" entered
// if(1==1) { // This works?
if (serialInstruction==97) {
//delay(1000);
for(int x=0;x<255;x++){
analogWrite(5,x);
delay(20);
//Serial.println(encoder_ticks);
}
}
delay(500);
}


void encoderA(){
encoder_ticks++;
}

0 comments

Please sign in to leave a comment.