Friday, March 18, 2011

A bit about objects...

All of us ooPic'ers of old know that it was sometimes a bit tedious to get Scott to fix up an object that didn't work the way we wanted it to... problem solved.

Scott tells me that in the Raptor IDE there is now an object editor. Want an object to work differently? How about an object he didn't think of? No problem... Roll your own.

The Raptor IDE will ship with all of the necessary ooPIC objects just like always, the difference is that there will no longer be hundreds of factory objects built in. Oh, it will ship with a handful of the most necessary objects to build a robot or electronic device but now there will be an 'object editor' that will allow you to create an object anytime you need one. Below is a very simple example of how it will be done:

'1. Open the IDE.
'2. Write this code:
'**********************************************************
'oLED Object
'**********************************************************
Dim IOLine As oIOLine

Sub TurnOn()
IOLine.Value = 1
IOLine.Direction = 1
End Sub

Sub TurnOff()
IOLine.value = 0
IOLine.direction = 0
End Sub
'**********************************************************
'3. Save this code as "oLED.osc" in the "Objects" directory, and you are done!

'To use your new object, create a new project in the IDE and write this code:
'**********************************************************
'Program that uses the oLED Object I just made.
'**********************************************************
Dim RedOne As oLED
RedOne.IOLine = 22
RedOne.TurnOn
'**********************************************************
'Pretty easy to me...But, Lets say that you wanted to vary the brightness of the LED.You can 'change the oLED Object in this way:
'**********************************************************'
'LED Object with brightness control
'**********************************************************
Dim PWM As oPWML
Alias IOLine as PWM.IOLine
Alias Brightness as PWM.Value

Sub TurnOn()
PWM.Operate = 1
PWM.Value = 255
End Sub

Sub TurnOff()
PWM.Value = 0
End Sub
'**********************************************************
'Now you can do this:
'**********************************************************
'Program that uses the oLED I just made.
'**********************************************************
Dim RedOne As oLED
Dim GreenOne As oLED
RedOne.IOLine = 22
GreenOne.IOLine = 23
RedOne.TurnOn
RedOne.Brightness = 75
GreenOne.TurnOn
GreenOne.Brightness = 20
'**********************************************************

1 comment:

  1. I believe that this is a step backward.
    Yes, I think the ability for users to build their own objects is a good idea.

    Buuuuttt, not including the full library that was available when the OOPicR was built is a mistake. You need to have a ton of objects ready to go to get people to switch from other controllers.

    ReplyDelete