Page 1 of 1

Creating a string to be used in a digital output statement

Posted: Thu Mar 19, 2026 9:36 pm
by Billduck1302
With a Arduino Mega, I want to send a "1" to digital output, say D4.
The "D" will be static. But the port number needs to change.

For example I will have a loop where I increase the integer value of PIN,and send 0 or 1 in a digital write.

In the following statement, for a digital output, the variable "PIN" is an integer.

DigitalOutput = STRING ('D' + PIN) FC is ok with the ststement, but it prints "69"

Any help is paareciated.

Re: Creating a string to be used in a digital output statement

Posted: Fri Mar 20, 2026 2:19 am
by mnfisher
The easiest way to do this is with a little C.

For example for port d (assuming the pin is set as an output)

PORTD |= (1 << FCL_PIN);

Will turn on 'pin' without affecting other pins in port d

Martin