Desvejk

PoweredUp device number as a variable

Recommended Posts

A question for the PoweredUp app users. 
Can the device number of the PoweredUp hub be set as a variable?

This would make coding with multiple hubs much easier. 
 

The coding example does not run the motor.

When the variable is removed the motor runs when the device number is set 1…4

Am I coding the variable correctly or does the coding block require a number?

Variables as device number

 

 

 

Edited by Desvejk
display image

Share this post


Link to post
Share on other sites

That works fine, but as far as I remember numbers are internally 0...3

This might be the reason why it does not run......

Share this post


Link to post
Share on other sites

Thanks Lok24,

Thanks so much looks like it worked!

I have changed the code to assign the internal device number.

I wonder why internally 0...3 are used?

This is a great help.

variable as device number correct

 

Edited by Desvejk

Share this post


Link to post
Share on other sites
14 hours ago, Desvejk said:

I wonder why internally 0...3 are used?

Programming gurus. They always start at ground zero :D

Honestly, I believe this came from back in the days. And is also a logical approach: Bitwise, it saves you one bit, when you begin at 0 as a valid entry. Hardware wise, it also makes things easier, as zero is easily recognized by the chippies. Also, 4 entities, hubs, channels, whatever, can be unambiguously addressed using only 2 bits: 00, 01, 10, 11 in the dual system, corresponding to 0 ... 3 in the decimal system. When you want to start at 1 and want to address 4 "devices", you need 3 bits: 001, 010, 011, 100 - and 000 is simply wasted.

And this is not good for saving money on the hardware front. However, some people not always playing in the programming game believe that 0 is nothing, but that is not true ;) To alleviate that "problem", folks in the marketing department tell folks in the software department to "fix this". So they do: The first device/whatever is "1" with address "0" - as the marketing folks also told the programming folks to make it as cheap as possible.

:pir-huzzah2:

Best,
Thorsten 

Edited by Toastie

Share this post


Link to post
Share on other sites

I wish there was a "kudos" or "thank you" Button without having to make a separate post. The bit bit (hehe) was an excellent explanation. 

Share this post


Link to post
Share on other sites
23 hours ago, Lok24 said:

That works fine, but as far as I remember numbers are internally 0...3

This might be the reason why it does not run......

 

On 11/14/2022 at 2:38 PM, Desvejk said:

A question for the PoweredUp app users. 
Can the device number of the PoweredUp hub be set as a variable?

This would make coding with multiple hubs much easier. 
 

The coding example does not run the motor.

When the variable is removed the motor runs when the device number is set 1…4

Am I coding the variable correctly or does the coding block require a number?

https://flic.kr/p/2nZ9gxm

 

 

8 hours ago, Toastie said:

Programming gurus. They always start at ground zero :D

Honestly, I believe this came from back in the days. And is also a logical approach: Bitwise, it saves you one bit, when you begin at 0 as a valid entry. Hardware wise, it also makes things easier, as zero is easily recognized by the chippies. Also, 4 entities, hubs, channels, whatever, can be unambiguously addressed using only 2 bits: 00, 01, 10, 11 in the dual system, corresponding to 0 ... 3 in the decimal system. When you want to start at 1 and want to address 4 "devices", you need 3 bits: 001, 010, 011, 100 - and 000 is simply wasted.

And this is not good for saving money on the hardware front. However, some people not always playing in the programming game believe that 0 is nothing, but that is not true ;) To alleviate that "problem", folks in the marketing department tell folks in the software department to "fix this". So they do: The first device/whatever is "1" with address "0" - as the marketing folks also told the programming folks to make it as cheap as possible.

:pir-huzzah2:

Best,
Thorsten 

Thanks Thorsten,

That was an excellent explanation.

It makes perfect sense and I understand it completely.

The underlying issue with the PoweredUp app is the lack of documentation.

There have been so many issues that I have faced that would have been so much easier had the reference material been available.

The work of so many who have put material online is much appreciated, but Lego has seriously fallen short with this.

It's a shame because the product is really good and I have been able to implement so many great solutions.

Brave Des

38 minutes ago, Sunil766 said:

I wish there was a "kudos" or "thank you" Button without having to make a separate post. The bit bit (hehe) was an excellent explanation. 

Agreed "kudos" for the "bit bit"

Share this post


Link to post
Share on other sites
5 hours ago, Desvejk said:

The underlying issue with the PoweredUp app is the lack of documentation.

It was promised for end of 2022.

Share this post


Link to post
Share on other sites
14 hours ago, Desvejk said:

Agreed "kudos" for the "bit bit"

Thank you very much, but it all goes back to day one of making computers, I believe ;)
 

Spoiler

 

Fun fact: The same thing happened to assigning letters to a floppy drive (or the like): You select drive 1 pulling line S0, and drive 2 with S1 and so forth. A drive 0 was not thinkable - as it did physically exist :D. The folks making operating systems had the same issue - and Bill Gates and companions decided to go away from numbers, and call drive 1, which is addressed by the floppy controller via selecting the S0 line as drive "A". Now, "A" is usually not regarded as "0" :pir-laugh:. Next up was "The Twist" in the 34 ribbon cable connecting two floppy (or hard) drives to one bus. That twist (marketing department :D) made drive 0 aka A to drive 1 aka A. Shugart drives were always factory delivered with drive A selected by S0, but on an IBM/compatibles, drive A was selected by S1, and drive B by S0 ...

So much for computing gurus and marketing masters.

 

Best,
Thorsten

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.