Defining Objects

DocZaf

Member
Is it possible to define objects or structures in PicBasic?

Something along the lines of...


Code:
Object
  Id = b0
  length = b1
  nameab = w1
  namecd = w2
  nameef = w3
  namegh = w4
End Object
 

westaust55

Moderator
Further to nick12ab's advise, there is no objecy structure in PICAXE BASIC.
So while you can define alias names as nick has stated

you cannot create an object as per your example and refer to a field/element such as Id.length
 
Last edited:

Buzby

Senior Member
objects or structures in PicBasic?

The OP is not asking about PICAXE BASIC.

I think that PicBasic does have objects and user defined types, but it's not PICAXE.

Cheers,

Buzby
 

hippy

Ex-Staff (retired)
If prepared to jump through some hoops you can create object-like structures with PICAXE. So the following is possible to flash independent LED's at varying speeds ...

Code:
led0.pin = B.0 : led0.pause = 1000
led1.pin = B.1 : led1.pause = 1500
Do
  bPtr = led0 : Gosub FlashLed
  bPtr = led1 : Gosub FlashLed
  Pause 100
Loop
The full code is ...

Code:
#Picaxe 18M2

Symbol reserveW0  = w0  ' b1:b0
Symbol reserveW1  = w1  ' b3:b2

Symbol led0       = 4   ' b4
Symbol led0.time  = w2  ' b5:b4
Symbol led0.pause = w3  ' b7:b6
Symbol led0.pin   = b8  ' b8

Symbol led1       = 10  ' b10
Symbol led1.time  = w5  ' b11:b10
Symbol led1.pause = w6  ' b13:b12
Symbol led1.pin   = b14 ' b14

led0.pin = B.0 : led0.pause = 1000
led1.pin = B.1 : led1.pause = 1500

Do
  bPtr = led0 : Gosub FlashLed
  bPtr = led1 : Gosub FlashLed
  Pause 100
Loop

FlashLed:
  b0 = @bPtrInc : b1 = @bPtrInc
  b2 = @bPtrInc : b3 = @bPtrInc
  w0 = w0 + 100
  If w0 >= w1 Then
    w0 = w0 - w1
    Toggle @bPtr
  End If
  bPtr = bPtr - 3
  @bPtrDec = b1 : @bPtr = b0
  Return
 

SAborn

Senior Member
Ok, now we know how Hippy spent his Xmas day :rolleyes: writing code examples, what a dedicated person he is. :cool:
Then that can be a more fun day than a visit to the outlaws (err inlaws)
 

westaust55

Moderator
Nothwithstanding typos (and that was before we opened the wine bottles for Christmas Day lunch) :mad:
I guess as nick12ab put it back in post 2 PICBASIC or PICAXE BASIC?

As per the sticky post: http://www.picaxeforum.co.uk/showthread.php?7679-Read-Me-First!
The PICAXE Forums have been designed to facilitate the flow of useful, appropriate and fun information about the PICAXE system.
This is a forum that is, for PICAXE microcontrollers as produced by Revolution Education together with questions on associated items used in projects with PICAXE chips.

While some members here do know about programming "raw"/native PIC chips in assembler and other languages these are not the intent of this forum.
As some folks do talk about "PIC" when they mean PICAXE, hence the request for clarification by nick12ab at post 2.
 

DocZaf

Member
Thank You Everyone for your help,
And its PicAxe-Basic I meant and not PicBasic.

Merry Christmas To You All Too!


Zaf
 

mrburnette

Senior Member
Is it possible to define objects or structures in PicBasic?

Something along the lines of...


Code:
Object
  Id = b0
  length = b1
  nameab = w1
  namecd = w2
  nameef = w3
  namegh = w4
End Object
Yes, you can build structures in a crude sense but all storage is public, although you can elect to keep RAM quasi-hidden from routines... only subroutines since PICAXE Basic does not support functions. To get an idea of how such things can be coded, you may wish to refer to a couple of my blog posts:
http://www.picaxeforum.co.uk/entry.php?36-Extending-PICAXE-named-variables-by-300-or-more!

http://www.picaxeforum.co.uk/entry.php?39-IR-set-18M2-clock-implemented-into-AXE133Y-OLED-display

Just keep your expectations reasonable and remember you are working with a uC that has constrained resources.

- Ray
 

westaust55

Moderator
Thank You Everyone for your help,
And its PicAxe-Basic I meant and not PicBasic.

Merry Christmas To You All Too!


Zaf
Although a little late,
Welcome to the PICAXE forum.

As you can see, it is good practice to refer to the microcontrollers as PICAXE rather than just PIC to help avoid confusion.
 
Top