PDA

View Full Version : Another BS2 (PBasic) substantial program translated to the Propeller (SPIN)



SamMishal
07-06-2009, 08:38 AM
Hi All,
One the·techniques of teaching is to teach a new skill by comparing and contrasting it to an already known skill. To that end I have already posted once before a translation of a substantial program written in PBasic for the BS2 into Spin so as it would run very much in the same manner on the Propeller.
See this posting http://forums.parallax.com/showthread.php?p=818815 (http://forums.parallax.com/showthread.php?p=818815)
In this posting I am enclosing another translation of another substantial program from PBasic to SPIN.
This program however, makes use of the FullDuplexSerialPlus library object ·that appears in the PEK library. This is to help with the program action but also to introduce the BS2 programmer to the concept of Objects in SPIN.
The·benefit·of this to people learning the Propeller and Spin is that they can put the two programs side by side and be able to immediately see how the constructs they are already familiar with from their experience with PBasic and the BS2 are translated into constructs within the Spin language. I am hoping this will be an aide for people trying to learn Spin.
The program is also useful. It allows you to use a Sony IR remote control to act as a numerical Keypad for number entries. The Spin program is a translation with an additional improvement of a program given in the Stamp In Class course called “IR Remote for the Boe-Bot”. The program appears on pages 81.
http://www.parallax.com/Store/Education/KitsandBoards/tabid/182/ProductID/322/List/1/Default.aspx?SortField=ProductName,ProductName (http://www.parallax.com/Store/Education/KitsandBoards/tabid/182/ProductID/322/List/1/Default.aspx?SortField=ProductName,ProductName)
The Spin program has instructions at the top that should be read to understand how the program works. Also, the program should be read in light of the information given in the Course Work.
The PBasic program that appears in the book on page 81 is a culmination of techniques and routines developed in earlier chapters and gradually evolved. Therefore to appreciate the SPIN version you need to read the chapters in the book and also read the PBasic program·intently before you start reading the SPIN program. Also make sure to compare and contrast the programs in Spin and PBasic to gain the most benefit.
A future program will be one that will combine this program and the one previously posted to allow a person to select an RTTTL song from a list of songs rather than to just play all the songs in succession as it currently does.
See if you can do this before I post the solution.
I hope this will be of use .....enjoy
Samuel
Note for Spin programmers:
The program is deliberately avoiding too much use of objects to make the program more friendly to the BS2 programmer. However, the program can be made into an object. Especially the methods for emulating the BS2 commands. Note: they are based on the ones in the BS2_Functions library object but are not the same. They have been modified and the program will not work with the equivalent ones that appear in the BS2_Functions object.

JonnyMac
07-06-2009, 09:52 AM
Sam,

If you ever want to go beyond the SIRCS basics I've created a PASM object that will detect an SIRCS code in its own cog and will even tell you how many bits it contains (usually 12 or 20 bits, and my DVD remote sends a mix -- the reason I created the object). The object allows you to enable reception and then check to see if a code has arrived allowing your Spin program to do other things until a code actually shows up; if your program is okay with waiting the then the .rx method makes it really easy.

obex.parallax.com/objects/477 (http://obex.parallax.com/objects/477)

SamMishal
07-06-2009, 10:29 AM
Hi Jonny
·
Your PASM object is very neat. However, I am trying to keep the program as
close as possible to the original BS2 program as detailed in the book.
·
The idea is for people to see how PBasic code·syntax corresponds to SPIN syntax.
·
Since the whole concept of Objects is a new thing for BS2 programmers I tried to
only introduce it SLOWLY with objects that do a SIMILAR function to what they are used
to doing in the BS2 like the FullDuplexSerialPlus object to replace the Debug command.
·
This helps to keep the·transition to·surmountable·hurdles and fathomable actions. Once a BS2 programmer
becomes comfortable with SPIN and the Propeller then the differences can·be gradually introduced
and more power can be utilized.
·
My next program will combine the two previous programs I have posted. This will not be something that
they can do easily with the BS2, but it will give a taste of the extra power while still maintaining the
familiarity to a maximum.
·
In the combined program I am going to introduce the Object model by making both programs into
objects and then have a top-level that uses them.
·
Once the BS2 programmer becomes familiar with such stuff then the use of the OBEX becomes a
simple jump.

·
Sam
·