Skip to content

Timer predicates

Tushar Semwal edited this page Oct 18, 2017 · 5 revisions

The arguments passed to a predicate can take three forms - Input, Output or Both, and are denoted by symbols +, - and ? respect

AgPi also provides Timer based predicates which allow for accurate delay and timing functionalities:

  1. delay(+T): Used to apply a delay of t milliseconds.

    • t: Time in milliseconds.
  2. delayMicroseconds(+T): Used to apply a delay of t microseconds.

    • t: Time in microseconds.
  3. millis(-T): It returns a number (T) representing the number of milliseconds since the program called one of the AgPi functions. It returns an unsigned 32-bit number which wraps after 49 days.

    • T: Time in milliseconds returned by the function.
  4. micros(-T): It returns a number representing the number of microseconds since the program called one of the AgPi functions. It returns an unsigned 32-bit number which wraps after approximately 71 minutes.

    • T: Time in microseconds returned by the function.


Example for LED blinking:

  • Commect a LED to Raspberry Pi at GPIO pins 1 (HIGH) and 0 (LOW).
  • Write the following code in a prolog file(in the working directory).
    Blink_Led
  • Now start prolog with sudo permission(very important):
    $ sudo swipl
  • Consult the platform_pi.pl using:
    ?- consult('platform_pi.pl').
    This will load all of the Tartarus predicates.
  • Execute the command:
    ?- start_peripherals.
  • Execute the following command to see the LED blink and the output of millis command on terminal.
    ?- start.
Clone this wiki locally