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

Pin control blocks treat Constants (NumberBlocks) differently... but why? #153

Closed
TonyCallear opened this issue Mar 31, 2016 · 0 comments
Closed

Comments

@TonyCallear
Copy link
Collaborator

Code in many pin control blocks generate different code depending on whether integer constants are given (instance of NumberBlocks) or other kinds of valid input (Variables, numberlists). Usually this just means setting pinMode once in Setup rather than using a special function.

Does anyone know why this is done?

It can create some odd bugs, which seem easy to fix but perhaps I just don’t understand why NumberBLock should be “special”?

eg.

al0

Works and does something useful. If pin 5 is momentarily brought LOW an LED/resitor connected to it are powered on.

It generates...

void __ardublockDigitalWrite(int pinNumber, boolean status)
{
  pinMode(pinNumber, OUTPUT);
  digitalWrite(pinNumber, status);
}

void setup()
{
}

void loop()
{
  if (__ardublockDigitalRead(5))
  {
    __ardublockDigitalWrite(5, HIGH);
    delay( 5000 );
  }
}

but

al1

Does not work. It generates...

void setup()
{
  pinMode( 5 , INPUT);
  pinMode( 5 , OUTPUT);
}

void loop()
{
  if (digitalRead(5)) // Pin is in OUTPUT mode!
  {
    digitalWrite( 5 , HIGH );
    delay( 5000 );
  }
}
TonyCallear added a commit to TonyCallear/ardublock that referenced this issue Apr 14, 2017
Stop treating numberblocks as a special case. See issue taweili#153
InputPullup. Correct socket type so it can be used.
Toggle that works with variables and maths denoting pin number.
e-Mole pushed a commit to e-Mole/ardublock that referenced this issue May 16, 2017
Stop treating numberblocks as a special case. See issue taweili#153
InputPullup. Correct socket type so it can be used.
Toggle that works with variables and maths denoting pin number.
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