
5: BASIC Stamp Command Reference – TOGGLE
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 327
TOGGLE
BS1 BS2 BS2e BS2sx BS2p
TOGGLE
Pin
Function
Invert the state of an output pin.
•
Pin
is a variable/constant/expression (0 – 15) that specifies which
I/O pin to set high. This pin will be placed into output mode.
Explanation
TOGGLE sets a pin to output mode and inverts the output state of the pin,
changing 0 to 1 and 1 to 0.
In some situations TOGGLE may appear to have no effect on a pin’s state.
For example, suppose pin 2 is in input mode and pulled to +5V by a 10k
resistor. Then the following code executes:
DIR2 = 0 ' Pin 2 in input mode.
PIN2 = 0 ' Pin 2 output driver low.
DEBUG ? PIN2 ' Show state of pin 2 (1 due to pullup).
TOGGLE 2 ' Toggle pin 2 (invert PIN2, put 1 in DIR2).
DEBUG ? PIN2 ' Show state of pin 2 (1 again).
--or--
DIR2 = 0 ' Pin 2 in input mode.
OUT2 = 0 ' Pin 2 output driver low.
DEBUG ? IN2 ' Show state of pin 2 (1 due to pullup).
TOGGLE 2 ' Toggle pin 2 (invert OUT2, put 1 in DIR2).
DEBUG ? IN2 ' Show state of pin 2 (1 again).
The state of pin 2 doesn’t change; it's high (due to the resistor) before
TOGGLE, and it’s high (due to the pin being output high) afterward. The
point is that TOGGLE works on the OUTS register, which may not match
the pin’s state when the pin is initially an input. To guarantee that the state
actually changes, regardless of the initial input or output mode, do this:
PIN2 = PIN2' Make output driver match pin state.
TOGGLE 2 ' Then toggle.
--or—
OUT2 = IN2 ' Make output driver match pin state.
TOGGLE 2 ' Then toggle.
1
2
e
2
sx
2
p
2
1
NOTE: Expressions are not
allowed as arguments on the BS1.
The range of the Pin argument on
the BS1 is 0 – 7.
1
2
e
2
sx
2
p
2
1
2
e
2
sx
2
p
2
Содержание BASIC Stamp 1
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...