GIRA / PhysicalBits

A web-based programming environment for educational robotics that supports live coding and autonomy using a hybrid blocks/text programming language.
https://gira.github.io/PhysicalBits/
MIT License
18 stars 5 forks source link

UziScript and Smalltalk #1

Closed kristiank closed 4 years ago

kristiank commented 4 years ago

I see tremendeous potential in all your work (Physical-Etoys and UziScript) and I really enjoy the feeling of how close your projects have brought the electronics "outer world" into the virtual computer. But, alas, I am having trouble starting to use arduino in Smalltalk.

For example, I am able to see input values change in the UziControlPanel, but how do I get the same readings out in a Smalltalk script or Workspace? Could you provide a very small example, e.g. reading the value of analog input A0 and assign it to a variable in Smalltalk?

(What is the best way to contact you?)

Thank you!

RichoM commented 4 years ago

Hi Kristian, thank you for your comment.

The smalltalk api we have right now is not very nice but the following snippet should help. Make sure to use the latest version, though. And let me know if it works for you.

"Connect to the board"
controller := UziController new.
controller connectOnPort: 'COM3'.

"Check connection"
controller isConnected.

"Disable idle timeout"
controller reportingIdleTimeout: nil.

"Get a pin value"
controller setPin: 'A0' report: true.
a0 := (controller getPin: 'A0') value.

"Set a pin value"
controller setPin: 'D13' value: 1.
controller setPin: 'D13' value: 0.

"Run a program"
program := Uzi compileString: '
    task blink13() running 5/s { toggle(D13); }'.
controller run: program.

"Stop current program"
controller run: UziProgram empty.

"Install the running program in EEPROM"
controller installRunningProgram.   

"Disconnect"
controller disconnect.
kristiank commented 4 years ago

Thank you so much, you answered so many of my future questions. It took me a while to update to the newest version, but this morning I got everything working. Also, I almost got it working with the first release version's code, which was a very good practice for me to do. I will keep you updated and also push Estonian, Finnish and Swedish translations. Thank you again.