Arduino digital read fix


#1

New to mBlock, not using makeblock products. I am evaluating the use of mBlock to teach Arduino programming to middle and high school students. It actually looks pretty good as an intermediary step. I like going from Scratch to a direct upload to Arduino.

However, the digitalRead block is faulty as it reads an integer value (1,0) but is structured as a logical value (true, false) with pointy ends. I’m not sure if I’m using the right words to describe this but I know it doesn’t work. One solution I found is to correct the s2e file for Arduino to substitute “digitalRead({0}) == 1” for “digitalRead({0})”. This does work.

What I don’t know though is whether I can change the install file to install the correct line, or whether I can provide students with an easy way to change it in their installations. (My course is being provided via Moodle California-wide, so its not easy to step people through the replacement. Anyone have any suggestions?

Milt


#2

Im not sure if this helps much but boolean values are very often coerced from other types especially when a programming language does not actually have a native boolean type.
true = 1
true = "1"
false = 0
false = “”

not all languages will agree on “0” since that depends on how a string is coerced into an int.
Test in an if statement to see for yourself.


#3

Yeah, thanks. I found out that the way it is set reads true if there is 5V and false if there is 0V. So it can work as a boolean. Thanks for jugging my noggin.