Have any questions?

hello@appshed.com

LOGO Command Reference

5.0/5 rating (5 votes)

The LOGO commands are used for controlling the AppCar and other Robotics & IoT projects by AppShed.

  • Driving
  • Motor Control
  • Output Pins
  • Servo
  • Logic
  • Loops
  • Variables
  • Operators
  • Program Flow
  • Other (Clear, Display)

 

Driving

The following commands are used for driving the AppCar. They will control two motors to achieve different driving directions:

FD x (or FORWARD) - Move forward x millimeters, Example: FD 100
BK x (or BACK) - Move Backward x millimeters, Example: BK 100
LT x (or LEFT) - Rotate the turtle x degrees left, Example: LT 45
RT x (or RIGHT) - Rotate the turtle x degrees right, Example: RT 45
ARCFL x Move in an arc going forward and left for x degrees, Example: ARCFL 45
ARCFR x Move in an arc going forward and right for x degrees, Example: ARCFR 45
ARCBL x Move in an arc going backward and left for x degrees, Example: ARCBL 45
ARCBR x Move in an arc going backward and right for x degrees, Example: ARCBR 45
ST x (or STOP) - Stop moving both motors
 
 

Motor Control

Motor control is similar to driving, but only controls one motor at a time. This can be used for other purposes, such as turning a winch/pulley. 
MAFD Motor A FD
MABK Motor A BK
MBFD Motor B FD
MBBK Motor B BK
 
 

Output Pins

Each of the pins can be controlled and set to different values. Pins can be used for the following purposes:
  • Digital - set a pin to 1 or 0 (on or off)
  • Analog - set a pin to a value from 0 to 1023 (this is the range from off to fully on)
  • Servo - set a servo pin to degrees of rotation 0 to 180

Digital 

Set a pin to 1 or 0 (on or off)

D0 1/0

Example

  • D5 0
  • D8 1

The same applies to all pins: D0 D1 D2 D3 D4 D5 D6 D7 D8 D9

 

Analog 

Set a pin to a value from 0 to 1023 (this is the range from off to fully on)

A0 0-1023 - Set pin A0 to value (no duration)

Examples

  • A3 753
  • A0 13

The same applies to all pins: A0 A1 A2 A3 A4 A5 A6 A7 A8 A9

 

Servo

Set a servo pin to degrees of rotation 0 to 180 (degrees)

SERVOx 0-180 - Set servo on pin x to 0-180 degrees.

Examples:

  • SERVO8 135

The same applies to all pins: SERVO0 SERVO1 SERVO2 SERVO3 SERVO4 SERVO5 SERVO6 SERVO7 SERVO8 SERVO9

 

 

Logic

 

IF Statements

If statements check a condition and runs the code only when the condition is true.

IF x = y [ .... ]

If x equals y then run the code ... inside the brackets.

Examples

  • Go FD if pin 1 is off 
    IF D1 = 0 [ FD 100 ]
  • Turn servo 6 to 45 degrees if anlaog input greter than 520
    IF A0 > 520 ( SERVO6 45 ) 

Rules

  1. The condition must compare two values. You can use any comparators, including:
    • = (equal)
    • != (not equal)
    • > (greater than)
    • < (less than)
    • >= (greater Ythan or equal)
    • <= (less than or equal)
  2. The code must always be inside brackets.
    • You can use any brackets, e.g. [...] (...) {...}
    • You can put any code inside the brackets, including other IF statements (i.e. nested IF )
    • Make sure you have a pair of brackets. This can get confusing when nesting IFs, and nesting REPEATs.

 

Input Pins

Pins can be used as inputs. This is done when you need to read/discover the value of a sensor or button attached to the pin. For example, if a button is connected to pin 3, when the button is pressed, D3 will be 1.

D0 D1 D2 D3 D4 D5 D6 D7 D8 D9

Analog sensors (such as light sensors, temperature etc) can be connected to A0. The values range from 0 (completely off) to 1023 (completely on). There is only one analog input pin on the NodeMCU/ESP8266. e.g. the sensor valuu/reading on A0 might be 500.

A0

 

LOOPS 

 

LOOP

LOOP [ ... ] - Runs the code inside the brackets repeatedly and indefinitely, in a loop. 

Any Logo commands can go inside the brackets (except another LOOP). This allows you to repeat a command, e.g. checking the value of a pin. LOOPs are normally used to respond to changes in the value of a pin.

Example: Turn on LED D0 when A0 above a 500.

LOOP [ IF (A0 > 500) (D0 0) ]

 

 

REPEAT

Repeats allow you to repeat a block of code x number of times:

   REPEAT x [...]

Repeat the code x times.

Examples

  • Draw a square w
  • ith 50mm sides
     REPEAT 4 [ FD 50 RT 90 ]
  • Wave the servo back and forth
    REPEAT 2 { SERVO7 180 WAIT 500 SERVO7 0 WAIT 500 }

 

Rules

  1. The number of repeats (x) must be an integer
    • Do not use very large numbers (e.g. over 10) as the code might fail... remember the Node has very limited memory capacity.
  2. The code must always be inside brackets.
    • You can use any brackets, e.g. [...] (...) {...}
    • You can put any code inside the brackets, including other IF statements (i.e. nested IF )

 

 

 

Variables

 You can create variables in logo and use them to store values. You can change those values in your logo code, based on conditions (e.g. IF something happens, then change the variable). 

When using a variable, a colon must be put in-front of the variable name, e.g. :var1

You can use variables in your code in many ways, for example:

  • Set a Pin value,
       e.g. D1 :var1
    (this will set D1 to whatever var1 is. Obviously in this case var1 should either be 1 or 0, otherwise itis meaningless.)

  • Set a Drive command, 
       e.g. FD :distance
    (distance should hold a positive integer value, e.g. 100)

  • Use variables in an IF condition,
       e.g. IF :distance > 100
    (if the value of distance is 101, then the condition is true)

  • Use variables in a REPEAT,
       e.g. REPEAT :var1
    (var1 should be a positive integer, like 4)

 

MAKE

Use MAKE to define a new variable, or set a variable to a new value.

When creating or setting the value of a variable, the variable name must start with a double quote, e.g. MAKE "var1 1

Examples

MAKE "var1 4
// sets var1 to the value of 4

MAKE "var1 = :var1 + 1
// increments the value of var1 by 1, e.g. 4+1=5

 

Operators

The operators are used to carry out mathematical arithmetic. 

+ - * / %

Most operators have the format: {value1} + {value2}
(in this case we use +, but it could be + - * / %)

The {value} can be any number, or or could be another variable. 

Examples:

1 + 1
3 % 2
:var1 + 1
:var1 * :var2

 

In most cases operators are used to assing a value to a variable. e.g.

MAKE "var1 512
MAKE "var2 = :var1 + 1
MAKE "var3 = :var1 * :var2

 

+ (add)

Add two values.

{value1} + {value2}

 

- (subtract)

{value1} - {value2}

 

* (multiply)

{value1} * {value2}

 

/ (divide)

{value1} / {value2}

 

% (modulus)

{value1} % {value2}

 

 

Program Flow

There are various commands that can be used to control the flow of the program. Used in the right way these can achieve very clever outcomes. But they should be used carefully as they can cause unexpected results if used improperly.

 

WAIT

WAIT x - Pause execution for duration (x).

No state change, all pins remain as they are. No further commands are executed until the duration passes. 

(This uses Arduino millis code but does not stop the loop() process.)

 

DELAY

DELAY x - Pause execution for duration (x) for the entire device. All other  commands will also be paused during this time. No commands or loops will run until the delay is complete.

(This uses Arduino delay() function)

 

Labels

Add a label at any position in your code. This is used in conjunction with the GOTO command. On it's own, labels do nothing. The format is the label name followed by a colon.

<name>:

The <name> of the label can be alphanumeric, but no spaces or special characters.

Example

checkpins:

 

GOTO 

GOTO is used to jump to a specific LABEL. The code will continue running from that LABEL. Any code will be skipped.

You can add multiple LABELS and GOTO commands. These are often used with IF conditions, e.g. IF a-certain-thing-happens, GOTO aaa and IF another-thing-happens GOTO bbb.

You can use GOTO to jump to the same LABEL many time over.

GOTO <label>

Example

IF (D1 = 0) [GOTO aaa]
IF (D1 = 1) [GOTO bbb]

aaa:
<some code>
   GOTO ccc
bbb:
<some other code>
GOTO ccc
ccc: 
<the rest of your code>

 

 

Functions

You can create functions and call them from your code. This allows you to reduce the amount of code, and simplify repetitive tasks. For example the code to draw a square could be put into a function

  1. Save the code for the function in the Function Code Box
    (e.g. for Function 1, save the code in the input for FN1)
  2. In your main code box, you can call the function, e.g. FN1 FN2
    (This code will call function 1, then call function 2)
  3. Functions can use any code (IF, REPEAT, and other Functions.)
    DO NOT call a function from itself, so do not put FN1 into the code for function 1. This creates and indefinitely loop, and the universe will explode.

Parameters

You can use parameters with functions to set values. Parameters are defined as :VARx (x is 0-9). (Parameters are similar to variables, but they are used when passing a value into a Function.)
(NOTE the colon : before the VAR)

:VAR1  :VAR2  :VAR3  :VAR4  :VAR5  :VAR6  :VAR7  :VAR8  :VAR9

Examples

  • A function to draw a square has a variable to define the size of the square.
    Function 1: REPEAT 4 [ FD :VAR1 RT 90 ]
  • A function to wave a servo x number of times
    REPEAT 2: :VAR1 [ code to wave ]
  • Wave 3 times, going from 45 degrees to 135 degrees
    FN1 3 45 135
    Code:  REPEAT :VAR1 [ SERVO6 :VAR2 WAIT 500 SERVO6 :VAR3 WAIT 500 ]

 Rules

  • If a function uses parameters, you have to pass the parameters when calling the function.
    e.g. FN1 50 (to draw the 50mm square)
        But this would fail: FN1 (without a parameter)
    FN2 5 (to wave 5 times)
  • Functions can use multiple parameters (up to 9)
  • You have to supply the correct number of parameters, so check the function code to see which are required.

 

 

Other Commands

CLEAR

This will clear all the Logo code running on the device. 

Motors will stop. Any code that is currently running or in the queue will be deleted. The LOOPs will stop running.

 

DISPLAY

This will display the value of a pin (or an expression) in the app.

DISPLAY A0
DISPLAY DHT2.TEMP * 9 / 5 + 32

(This requires an input box on the screen. Set the Custom Class for the item to "logodisplay")

 

 

 

 

 

 

Share this product

appshed name white text 250

Copyright © 2022 AppShed Limited

AppShed Support
Customer Support

We are online and available to help teachers/educators using AppShed. How can we help you today?

Chat, call or email support@appshed.com