Setting pins to high low at the same time

Hi folks.

so newish to fidgeting with arduino.
Got a stepper motor sort of running with transistors.
But its wierd.
And made it worse with each attempt. I used the same code sheet so wat i have left is a mess, and a vibrating motor. >:(

Anyways the problem.
How would one set selected pins to be....
eg: pins 2,3,4,5 to
HIGH,LOW,LOW,HIGH in one line of code.

Thanks in advance.

usually it's not really needed, there are very few physical stuff that react to a few microseconds deltas. but if you really want to have the best possible synchronicity the hardware can offer then read about Port Registers

e.g. from the example there

DDRD = DDRD | B11111100;  // this is safer as it sets pins 2 to 7 as outputs
	                  // without changing the value of pins 0 & 1, which are RX & TX 
PORTD = B10101000; // sets digital pins 7,5,3 HIGH and the others LOW

Hahaha... ty so very much.
I was just reading about it.
Ill give it a whirl once i have a better idea on how it works.
Its really good advice though.

Had a good look at port manipulation.
Seems kinda risky.
And im not sure im willing to go that route.

Any other way to to get desired pins to do the desired result.

Nope :slight_smile:

and it's not that risky. just play with a bit mask and avoid playing with 0 and 1 as they are your Serial line

I don't understand. Many others have gotten stepper motors to work using separate lines of code and little consideration of the timing.

digitalWrite(...) sets a single pin and works on any Arduino. Port manipulation sets multiple pins IN THE SAME PORT simultaneously but may be specific to just a few Arduinos. I do not know anything inbetween.

There is a fastport library that may do as you asked but I am unfamiliar with it and it is unnecessary for your stepper motor.

"Two or three hours spent thinking and reading documentation solves most programming problems."

After reading this "Quote"
Ill do exatly this after a short break.

Ty all for your time :slight_smile: