Skip to content

pinToggle

gicking edited this page Jan 27, 2018 · 3 revisions

Description

Toggle the output state of an I/O pin from low (= 0V) to high (= 3.3V or 5V, depending on supply).

If the pin has been configured as an OUTPUT via pinMode() or portMode(), this command toggles the pin output state.

Notes:

  • after reset all I/O pins are configured as INPUT
  • if a pin is configured as INPUT*, pinToggle() has no effect.

Inclusion

  • defined in gpio.h
  • auto-loaded in main_general.h
  • no #define required

Syntax

pinToggle(pPort, pin)

Parameters

  • input:

    • pPort: address of port to set, e.g. &PORT_A
    • pin: pin you wish to set (0..7)
  • output:

    • none

Returns

  • Nothing

Example Code

The below code makes pin PD0 (=LED on STM8S Discovery) an OUTPUT and toggles it HIGH and LOW with 1s delay.

#include "main_general.h"   // board-independent main

void setup()
{
  pinMode(&PORT_D, 0, OUTPUT);    // set PD0 as output
}

void loop()
{
  pinToggle(&PORT_D, 0);          // toggle PD0 state
  delay(1000);                    // wait 1s
}

Relevant Tutorial

Notes and Warnings

To avoid damage

  • do not expose I/Os to voltages outside [-0.3V; Vdd+0.3V], else limit injection currents to the specificied limits
  • for OUTPUT pins assert that sink and source currents are below the specificied limits
  • do not directly connect two OUTPUT pins. If e.g. half-duplex is required, use a pull-up and OUTPUT_OPENDRAIN, instead

See also

Clone this wiki locally