Digital outputs automated in a MEGA

Post here to discuss any new features, components, chips, etc, that you would like to see in Flowcode.
Post Reply
Billduck1302
Posts: 16
http://meble-kuchenne.info.pl
Joined: Fri Dec 06, 2024 4:41 pm
Has thanked: 1 time

Digital outputs automated in a MEGA

Post by Billduck1302 »

I need to sample 14 voltages on a Lithium battery pack. I am using a relay board to address individual cells. For example, to get the Cell 1 voltage, I send "0" to a relay board pin, and "0" to another relay board pin. I note that the "output" command icon only allows the selection of a pin number (eg D22) and the value, 0 or 1.
It would be nice if I could have the pin numbers in an array and choose which element of the array to populate the "output" command icon pin #, such as "D22".
Thanks in advance.

mnfisher
Valued Contributor
Posts: 1635
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 142 times
Been thanked: 761 times

Re: Digital outputs automated in a MEGA

Post by mnfisher »

It's certainly possibly, if maybe cheating slightly...

First note that you can define pins in properties (as s single digital pin) and assign values in a calculation block

Pin = 1 to set pin high for example

Take a look at the code generated - i think it is set_pin('D', 2, 1); for d2 set highfor example.

Then use something like - on my phone so typing for is a pain...

Have an array of 2 character strings ("d2”, ”d3”...}

Then port is str[n][0] and pin is str [n][1] - '0'

The in a c block do set_pin(FCL_PORT, FCL_PIN, 1);

i will post on FC tomorrow...

Martin

mnfisher
Valued Contributor
Posts: 1635
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 142 times
Been thanked: 761 times

Re: Digital outputs automated in a MEGA

Post by mnfisher »

Hi Bill,

Okay - a simple example - I used an Arduino UNO - but it will work without change on a Mega. You'll need to add more ports to the 'switch' statement in the SetPins macro. It only handles ports B, C and D here.

Here I show toggling a pin set in properties (just once!) and then an array of three members toggled repeatedly.

Note that a 'neater' (ie quicker) way to do this would be to calculate the port address from the name ('B','C' etc) and write directly to the MCU registers. This would be quicker than using the switch statement - I do this here viewtopic.php?t=259&hilit=pullups - it uses the fact that the difference in address for each port is a constant.

Martin
Attachments
pins.fcfx
(10.49 KiB) Downloaded 5 times

Post Reply