Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pins as first-class value entity #1191

Open
supuflounder opened this issue Sep 21, 2020 · 1 comment
Open

Allow pins as first-class value entity #1191

supuflounder opened this issue Sep 21, 2020 · 1 comment

Comments

@supuflounder
Copy link

Is your feature request related to a problem? Please describe.
I want to write an app that can poll each analog pin (except A0) in turn, asking if it is connected to a plant that is too dry.

set pins to [A1, A2, A3, A4, A5, A6, A7]

Describe the solution you'd like
Pins as first-class value entities. I should be able to set a variable to a value of type "pin" and then use that variable as a place to read from or write to. This would allow me to have arrays of pin values so I could make multi-device applications, such as a plant-needs-water detector that can have an array of dryness values and an array of analog pins.

for(i from 0 to pins.size() - 1)
{
dryness = AnalogRead(pins[i]);
...process reading
color = ...value selected from R, G, Bk
set(LED[i] to color);

Describe alternatives you've considered
(A) A set of seven routines, each representing a single thread, each of which has "hardwired" one pin, all of which call the same function to set their light red.

forever do
{
value = AnalogRead(A1);
process_value(0, value)
}
forever do
{
value = AnalogRead(A2);
process_value(1, value);
}
and so on (I'm trying to use text here to represent blocks)

(B) A value block called "pin" which takes an integer and returns a pin number. So any place I could use a pin, I could use a value block pinFromInt(int). Then I could use an array such as
[10, 11, 12, 48, 47, 8, 7]
to represent A1..A7. This seems harder to explain than simply being able to write a simple array of pins, unless there is also a pinToInt where I could write
set pins = [pinToInt(A1), pinToInt(A2), ... pinToInt(A7)]
and then access it as
AnalogRead(pinFromInt(pins[i]))

I am again using text to represent what I want in blocks.

Additional context
The ability to use a single routine to look at pins in a loop came from an 11-year-old who will be "maintaining" this code. She did not quite express it as I have, (she could express the problem but not the computer-sciencey aspects of the solution) but somehow knew that there should be a way to sequence through all the analog pins.

@supuflounder
Copy link
Author

Another approach would be a "pinFromName(String)" value block, so I could store
set pins = ["A0", "A1", ..., "A7"]
and then do
dryness = AnalogRead(pinFromName(pins[i]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant