Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4829

General • GPIO pins dynamically set as input or output within C program?

$
0
0
Hi! I'm new to the RasPi, and the Pico, but the Pico brought me over from the Arduino world, so my mindset is a bit stuck there, so please forgive my question if it's obvious.

I'm wondering if it is possible to dynamically set (or re-assign) the input vs output function of an individual GPIO pin on the Pico?

For example, let's say GPIO 1 is set as a digital input, waiting for a high or low signal from another source.

If the signal on GPIO 1 is high, then the C program could assign GPIO 2 as an output , and run a routine to send data.

If the signal on GPIO 1 is low, then the C program could assign GPIO 2 as an input, and wait for input there.

...thus turning the Pico into more of what I believe to be a "state machine".

If this is possible, are there any simple "hello world" type examples of the C code I could try?

Thanks,

Best,
AJ

Statistics: Posted by ForgottenMachines — Thu Feb 08, 2024 10:07 am



Viewing all articles
Browse latest Browse all 4829

Trending Articles