Section Configure From Macros Text Scripts

Of course, all this great stuff of drawing, graphics, sounds, controls and math takes up room on your BASIC Stamp module, and in some cases you may not be able to modify the controller code to perform such operations.

Macros are simply text files that contain configuration information and can be used for the processing of data. Below is a simple macro.

V Use the Macro menu ^ Edit Macro with NotePad

V Provide a name, such as macroTest

V Answer yes to create (twice).

V Place text in file.

V Save file.

V Use the Macro menu ^ Run Macro, select the macro and open it.

'Macro to plot and show value in meter INIT:

' Define this macro as the default macro for data !DEFS (ME)

' Clear all plot objects !POBJ Clear

'Start a new plot !NEWP

' Enable plotting !PLOT ON

' Place graphic text

' Create meter

!O oMeter.Meter1=75,50,,,-100,100 ' set update value, format for 2 decimal places !O Meter1.U=[(AINVAL0),FORMAT,0.00]

' Use default routine when data arrives

!USED ON

ENDMAC

'Routine ran when analog data arrives DEFAULT:

' Update plot object controls

!O UPDATE

ENDMAC

This macro has two routines in it, INIT and DEFAULT and each ends with ENDMAC. INIT is run when the macro is opened. By specifying !USED ON, the DEFAULT routine is ran when analog data arrives. ALL comments must be on separate lines from the code in macros.

Here is a simple PBASIC code snippet test it.

x VAR WORD DO

FOR X = 0 TO 36 0 DEBUG DEC x,CR PAUSE 100 NEXT LOOP

Now, the combination of the Macro and BASIC Stamp plot the values and display in the meter from 0 to 360.

But what if we want the SIN values plotted instead? Manipulating Analog Data Before Plotting

We can stop StampPlot from automatically plotting the incoming analog data and manipulate the data before plotting it.

V At the end of the INIT: routine, before ENDMAC, add this:

' Use analog data for macro only - do not plot !USEA ON

V Change the DEFAULT Routine to this:

'Routine ran when analog data arrives DEFAULT:

' Plot analog channel 0 in red !ACHN 0,[[(AINVAL0),SIN],*,100],(RED) ' Update plot object controls !O UPDATE ENDMAC

!ACHN tells StampPlot to plot the value on a channel (0-9) in color specified. !ACHN 3,100,(BLUE)

Other Analog Data Processing Methods

Besides use of the Default macro, object controls can be used to be trigger event code when analog data, digital data or message data is received. This is performed using a specially structured name for these object controls.

Name beings with:

DA_ Event code will be processed when analog data arrives. DB_ Event code will be processed when digital data arrives. DM_ Event code will be processed when messages for the message list are received.

An example for analog data:

' DA_Hidden -- OBUTTON *****

!POBJ

oButton.DA_Hidden=72.,73.,10.

5.,Obj10,8

!POBJ

DA Hidden.V=

0

'-- Event Code

!POBJ l • 1

DA_Hidden.C=

'Local Channels(;

'Plot

on channel 0

1st

byte(;)

^AchN i • 1

0,[(AINVAL0)

,*,0

02],(ORANGE)

(;)

'plot

on channel 1

2nd

byte(;)

^AchN

1,[(AINVAL1)

,*,0

02],(RED)(;)

'plot

on channel 2

3rd

byte(;)

^AchN

2,[(AINVAL2)

,*,0

02],(BLUE)(;

!IFTH

[(AINVAL1),=

=,(AINVAL2)],==,1

~pwav beep(;)

!POBJ

UPDATE

A button is placed on the plot and named DA_Hidden. The button is set to be hidden - not visible (DAJHidden. V =0)

When analog data arrives the event code will be ran and 3 channels of analog data will be scaled by multiplying each value by 0.2 and plotted in Orange, Red and Blue.

If analog channel 1 is equal to analog channel 2 (the logical result of comparing them, 0

or 1, is equal to 1 the beep wav is played.

The plot objects are updated with current values.

One other way to trigger code on arrival of data is the use of the oAnalog object introduced in StampPlot Version 3 Release 2. oAnalog. C = ~PWAV beep (;) !STAT Value is (AINVAL0)

Macros (.spm files) may be opened directly by double-clicking them from Windows Explorer or from an Internet link. This will load StampPlot and bring up the macro.

DIY Battery Repair

DIY Battery Repair

You can now recondition your old batteries at home and bring them back to 100 percent of their working condition. This guide will enable you to revive All NiCd batteries regardless of brand and battery volt. It will give you the required information on how to re-energize and revive your NiCd batteries through the RVD process, charging method and charging guidelines.

Get My Free Ebook


Post a comment