This repository has been archived on 2024-09-22. You can view files and clone it, but cannot push or open issues or pull requests.
pbi-ide/help/BasicStampHelp/Content/LanguageTopics/Commands/BUTTON.htm

126 lines
8.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="6" MadCap:lastHeight="94" MadCap:lastWidth="853" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:PreloadImages="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" lang="en-us" xml:lang="en-us" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="Default.xml" MadCap:SearchType="Stem">
<head><title>BUTTON</title>
<link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
<script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
</script>
</head>
<body>
<h1 class="code">BUTTON</h1>
<div class="ImagePlusCaption">
<div class="Col2">
<p>
<img src="../../graphics/pgm_icon1.gif" border="0" alt="BS1 icon" title="BS1 icon" />
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" />
</p>
</div>
<p style="text-align: right;"><a href="../ExampleTopics/ButtonEx.htm" target="" title="" alt="" class="MCXref_0">BUTTON Example</a>
</p>
<p>&#160;</p>
</div>
<p class="clear">&#160;</p>
<p>&#160;</p>
<p class="PlainText">Syntax: <span class="keyword_in_text">BUTTON</span> <![CDATA[ ]]><i>Pin</i>,<i> DownState</i>,<i> Delay</i>,<i> Rate</i>,<i> Workspace</i>,<i> TargetState</i>,<i> Address</i></p>
<h2>Function</h2>
<p class="PlainText">Monitor and process a pushbutton input, perform auto-repeat, and branch to address
if button is in target state. Button circuits may be active-low or active-high.
</p>
<ul>
<li value="1"><b><i>Pin</i></b> is a variable/constant/expression* (0 - 15) that specifies
the I/O pin to use. This pin will be set to input mode.</li>
<li value="2"><b><i>DownState</i></b> is a variable/constant/expression* (0 or 1) that
specifies which logical state occurs when the button is pressed.</li>
<li value="3"><b><i>Delay</i></b> is a variable/constant/expression* (0 - 255) that specifies
how long the button must be pressed before auto-repeat starts. The delay is
measured in cycles of the <span class="keyword_in_text">BUTTON</span> routine. <i>Delay</i> has two special
settings: 0 and 255. If <i>Delay</i> is 0, <span class="keyword_in_text">BUTTON</span> performs no debounce
or auto-repeat. If <i>Delay</i> is 255, Button performs debounce, but no
auto-repeat. </li>
<li value="4"><b><i>Rate</i></b> is a variable/constant/expression* (0 - 255) that specifies
the number of cycles between auto-repeats. The rate is expressed in cycles
of the <span class="keyword_in_text">BUTTON</span> routine. </li>
<li value="5"><b><i>Workspace</i></b> is a byte variable used by <span class="keyword_in_text">BUTTON</span> for workspace.
It must be cleared to 0 before being used by <span class="keyword_in_text">BUTTON</span> for the first time
and should not be adjusted outside of the <span class="keyword_in_text">BUTTON</span> instruction. NOTE:
All RAM is cleared to 0 by default upon power-up or reset of the BASIC
Stamp. </li>
<li value="6"><b><i>TargetState</i></b> is a variable/constant/expression* (0 or 1) that
specifies which state the button should be in for a branch to occur (0=not
pressed, 1=pressed).</li>
<li value="7"><b><i>Address</i></b> is a label that specifies where to branch if the button
is in the target state.</li>
</ul>
<p class="PlainText">*<img src="../../graphics/bs1note.gif" style="vertical-align: super;" /> Note: expressions are not allowed as arguments on the BS1. The range
of the <i>Pin</i> argument on the BS1 is 07.</p>
<h2>Explanation<br /></h2>
<p class="PlainText">When you press a button or flip a switch, the contacts make or break a connection.
A brief (1 to 20-ms) burst of noise occurs as the contacts scrape and bounce against
each other. By scanning an input within a loop to ensure that the contact remains
in a specified state for a minimum duration, spurious multiple inputs caused by
contact noise can be eliminated. The <span class="keyword_in_text">BUTTON </span>instruction helps prevent this
noise from being interpreted as more than one switch action; this is the function
of the <i>Delay</i> parameter. (For a demonstration of switch bounce, see the demo
program for the <a href="COUNT.htm" target="" title="" alt="" class="MCXref_0">COUNT</a> instruction.) <i>Delay</i>, combined
with the <i>Rate</i> parameter, allows the programmer to control the rate at which
multiple inputs are accepted by the BASIC Stamp.</p>
<p class="PlainText"><span class="keyword_in_text">BUTTON</span> also lets PBASIC react to a button press the way your computer
keyboard does to a key press. When you press a key, a character immediately appears
on the screen. If you hold the key down, there's a delay, then a rapid-fire stream
of characters appears on the screen. <span class="keyword_in_text">BUTTON</span>'s auto-repeat function can be
set up to work much the same way. </p>
<p class="PlainText"><span class="keyword_in_text">BUTTON</span> is designed for use inside a program loop. Each time through the
loop, <span class="keyword_in_text">BUTTON</span> checks the state of the specified pin. When it first matches
<i>DownState</i>, <span class="keyword_in_text">BUTTON</span> begins the <i>Delay</i> countdown for auto-repeat.
Then, in accordance with <i>TargetState</i>, it either branches to address
(TargetState = 1) or doesn't (TargetState = 0).</p>
<p class="PlainText">If the switch stays in <i>DownState</i>, <span class="keyword_in_text">BUTTON</span> counts the number of
program loops that execute. When this count equals <i>Delay</i>, <span class="keyword_in_text">BUTTON</span>once again triggers the action specified by <i>TargetState</i> and <i>Address</i>. Hereafter,
if the switch remains in <i>DownState</i>, <span class="keyword_in_text">BUTTON</span> waits <i>Rate</i> number
of cycles between actions. The <i>Workspace</i> variable is used by <span class="keyword_in_text">BUTTON</span>
to keep track of how many cycles have occurred since the pin switched to
<i>TargetState</i> or since the last auto-repeat.</p>
<p class="PlainText"><span class="keyword_in_text">BUTTON</span> does not stop program execution. In order for its delay and auto
repeat functions to work properly, <span class="keyword_in_text">BUTTON</span> must be executed from within a
program loop.</p>
<center>
<img src="../../graphics/button_sch.gif" border="0" />
</center>
<div class="Col2">
<div class="MasterFoot">
<p MadCap:conditions="BSEconditions.BSEWebHelp (Primary)-INCLUDE"><a href="../../HomeTopics/HomePage.htm">Go to Welcome page</a>
</p>
</div>
</div>
<div class="Col2">
<div class="MasterFoot">
<p style="text-align: right;"><span class="ContactInfoProjectName">BASIC Stamp Help</span> <![CDATA[ ]]><span class="ContactInfoVersion#">Version 2.5.4</span> <![CDATA[ ]]></p>
<p style="text-align: right;">Copyright ©&#160;<span class="ContactInfoCompanyName">Parallax Inc.</span></p>
<p style="text-align: right;"><span class="SystemShortDate">8/8/2012</span>
</p>
</div>
</div>
<script type="text/javascript">/* <![CDATA[ */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-285614-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
/* ]]> */</script>
<script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
</script>
</body>
</html>