Go Down

Topic: Cycling through some motors (Read 496 times) previous topic - next topic


Anyone see anything wrong with this code? I am trying to rotate setting some motors to high/low as a test, but sometimes 3 come on, and it misses other ones. I don't see what could be wrong with this, but I just want to make sure before I go to the lab tomorrow.

When I tried some other code that shifted through the motors with names for the motors (m1) it would work individually on all of them except for skipping some.

Code: [Select]
void setup ()
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
pinMode(1, OUTPUT);
digitalWrite(1, LOW);
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
pinMode(3, OUTPUT);
digitalWrite(3, LOW);
pinMode(4, OUTPUT);
digitalWrite(4, LOW);
pinMode(5, OUTPUT);
digitalWrite(5, LOW);

void loop ()
 for(int i = 0; i < 5; i++)
   digitalWrite(i, HIGH);
   digitalWrite(i, LOW);


Beware that digital pins 0 and 1 are also used for serial I/O to the host (via the FTDI chip).  But since you're not using Serial.print(), that shouldn't matter.

Go Up