<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>触摸开关 &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/%E8%A7%A6%E6%91%B8%E5%BC%80%E5%85%B3/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Mon, 27 Apr 2020 18:00:53 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创] 在树莓派上使用触摸开关（touch switch）</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e6%a0%91%e8%8e%93%e6%b4%be%e4%b8%8a%e4%bd%bf%e7%94%a8%e8%a7%a6%e6%91%b8%e5%bc%80%e5%85%b3%ef%bc%88touch-switch%ef%bc%89/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e6%a0%91%e8%8e%93%e6%b4%be%e4%b8%8a%e4%bd%bf%e7%94%a8%e8%a7%a6%e6%91%b8%e5%bc%80%e5%85%b3%ef%bc%88touch-switch%ef%bc%89/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Sat, 22 Oct 2016 17:53:41 +0000</pubDate>
				<category><![CDATA[Raspberry Pi/树莓派]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Raspberry Pi]]></category>
		<category><![CDATA[touch sensor]]></category>
		<category><![CDATA[touch switch]]></category>
		<category><![CDATA[树莓派]]></category>
		<category><![CDATA[触摸开关]]></category>
		<guid isPermaLink="false">http://www.codelast.com/?p=8908</guid>

					<description><![CDATA[<p>
触摸开关／触摸传感器／轻触开关，是一种通过轻触就可以实现开关的电子器件，生活中随处可见，很多家用电器的操控界面都是触摸开关。<br />
本文中的触摸开关，是在树莓派OS运行的情况下，用来触发某个动作（例如，触摸的时候控制摄像头拍照）。<br />
<span id="more-8908"></span><br />
<span style="background-color:#00ff00;">『1』</span>触摸开关模块介绍<br />
淘宝上很容易买到，仅需2元，你没有看错，只要2元，就可以买到这样一个触摸开关模块。</p>
<blockquote>
<p>
		该模块是一个基于触摸检测IC（TTP223B）的电容式点动型触摸开关模块。常态下，模块输出低电平，模式为低功耗模式；当用手指触摸相应位置时，模块会输出高电平，模式切换为快速模式；当持续12秒没有触摸时，模式又切换为低功耗模式。</p>
</blockquote>
<p>它的外观：</p>
<div style="text-align: center;">
	<a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="touch sensor" src="https://www.codelast.com/wp-content/uploads/2016/10/touch_sensor.jpeg" style="width: 370px; height: 336px;" /></a></div>
<p>电路板上的圆圈处就是触摸位置。</p>
<p><span style="background-color:#00ff00;">『2』</span>电路接线<br />
这个触摸开关模块只有3个接口：<br />
SIG：信号输出，高电平表示正在触摸，低电平表示没有触摸<br />
VCC：接电源正<br />
GND：接地<br />
因此，我们可以把SIG接到树莓派的任意一个GPIO口上（在这里，我使用的是GPIO 8），并且用程序把该GPIO口设置为INPUT（输入）模式，再把VCC和GND分别接到树莓派的5V输出口以及GND口上。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
下面是面包板电路图：</p>
<div style="text-align: center;">
	<a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="touch switch bread board" src="https://www.codelast.com/wp-content/uploads/2016/10/touch-switch_bb.png" style="text-align: center; width: 792px; height: 440px;" /></a></div>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
下面是电路原理图：<br />
<a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="touch switch scheme" src="https://www.codelast.com/wp-content/uploads/2016/10/touch-switch_scheme.png" style="text-align: center; width: 370px; height: 295px;" /><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span></a><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『3』</span>软件控制<br />
这个就更简单了。我们直接使用WiringPi自带的gpio程序来周期性读取SIG所接的树莓派GPIO口的状态，读到1的时候就是有人触摸了开关，读到0就是没有人触摸，然后在发现有人触摸的时候，去调用其他程序（例如控制摄像头拍照）即可。<br />
下面是程序，用shell脚本就可以实现了，超简单：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &#34;Helvetica Neue&#34;, Helvetica, &#34;Hiragino Sans GB&#34;, &#34;Microsoft YaHei&#34;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">#!/bin/bash
</span>
<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">#&#160;A&#160;touch-switch&#160;control&#160;program.

</span>

<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">#&#160;the&#160;Raspberry&#160;Pi&#160;GPIO&#160;input&#160;pin&#160;number,&#160;namely&#160;the&#160;pin&#160;connected&#160;to&#160;the&#160;signal&#160;output&#160;pin&#160;of&#160;the&#160;toch-switch&#160;module&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span>
GPIO_PORT=8

<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">#&#160;set&#160;the&#160;specified&#160;GPIO&#160;port&#160;to&#160;INPUT&#160;mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;</span>
gpio&#160;mode&#160;<span class="hljs-variable" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(98, 151, 85); word-wrap: inherit !important; word-break: inherit !important;">$GPIO_PORT</span>&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">in</span>

<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">while</span>&#160;<span class="hljs-literal" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">true</span>
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">do</span>
&#160;&#160;&#160;&#160;SWITCH_STATUS=`gpio&#160;<span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">read</span>&#160;<span class="hljs-variable" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(98, 151, 85); word-wrap: inherit !important; word-break: inherit !important;">$GPIO_PORT</span>`
&#160;&#160;&#160;&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">if</span>&#160;[&#160;<span class="hljs-variable" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(98, 151, 85); word-wrap: inherit !important; word-break: inherit !important;">$SWITCH_STATUS</span>&#160;-eq&#160;1&#160;];&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">then</span>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">echo</span>&#160;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&#34;Pressed&#160;@&#160;`date&#160;+\&#34;%F&#160;%T\&#34;`&#34;</span>
&#160;&#160;&#160;&#160;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">fi</span>
&#160;&#160;&#160;&#160;sleep&#160;0.01
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">done</span></code></pre>
</section>
<p>程序也可以在我的<a href="https://github.com/codelast/raspberry-pi/tree/master/gpio/touch-switch" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">GitHub</span></a>上找到。<br />
那么，这么简单的一个小东西，有什么用呢？我们可以把我们经常需要树莓派做（但又没有固定周期）的一些任务，用这个触摸开关来控制，例如可以在摸它一下的时候，调用pacman -Syu来升级Arch Linux ARM。还可以怎么玩，全凭你的想像力了。</p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e6%a0%91%e8%8e%93%e6%b4%be%e4%b8%8a%e4%bd%bf%e7%94%a8%e8%a7%a6%e6%91%b8%e5%bc%80%e5%85%b3%ef%bc%88touch-switch%ef%bc%89/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>
触摸开关／触摸传感器／轻触开关，是一种通过轻触就可以实现开关的电子器件，生活中随处可见，很多家用电器的操控界面都是触摸开关。<br />
本文中的触摸开关，是在树莓派OS运行的情况下，用来触发某个动作（例如，触摸的时候控制摄像头拍照）。<br />
<span id="more-8908"></span><br />
<span style="background-color:#00ff00;">『1』</span>触摸开关模块介绍<br />
淘宝上很容易买到，仅需2元，你没有看错，只要2元，就可以买到这样一个触摸开关模块。</p>
<blockquote>
<p>
		该模块是一个基于触摸检测IC（TTP223B）的电容式点动型触摸开关模块。常态下，模块输出低电平，模式为低功耗模式；当用手指触摸相应位置时，模块会输出高电平，模式切换为快速模式；当持续12秒没有触摸时，模式又切换为低功耗模式。</p>
</blockquote>
<p>它的外观：</p>
<div style="text-align: center;">
	<a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="touch sensor" src="https://www.codelast.com/wp-content/uploads/2016/10/touch_sensor.jpeg" style="width: 370px; height: 336px;" /></a></div>
<p>电路板上的圆圈处就是触摸位置。</p>
<p><span style="background-color:#00ff00;">『2』</span>电路接线<br />
这个触摸开关模块只有3个接口：<br />
SIG：信号输出，高电平表示正在触摸，低电平表示没有触摸<br />
VCC：接电源正<br />
GND：接地<br />
因此，我们可以把SIG接到树莓派的任意一个GPIO口上（在这里，我使用的是GPIO 8），并且用程序把该GPIO口设置为INPUT（输入）模式，再把VCC和GND分别接到树莓派的5V输出口以及GND口上。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
下面是面包板电路图：</p>
<div style="text-align: center;">
	<a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="touch switch bread board" src="https://www.codelast.com/wp-content/uploads/2016/10/touch-switch_bb.png" style="text-align: center; width: 792px; height: 440px;" /></a></div>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
下面是电路原理图：<br />
<a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><img decoding="async" alt="touch switch scheme" src="https://www.codelast.com/wp-content/uploads/2016/10/touch-switch_scheme.png" style="text-align: center; width: 370px; height: 295px;" /><br />
<span style="color: rgb(255, 255, 255);">文章来源：</span></a><a href="http://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">http://www.codelast.com/</span></a><br />
<span style="background-color:#00ff00;">『3』</span>软件控制<br />
这个就更简单了。我们直接使用WiringPi自带的gpio程序来周期性读取SIG所接的树莓派GPIO口的状态，读到1的时候就是有人触摸了开关，读到0就是没有人触摸，然后在发现有人触摸的时候，去调用其他程序（例如控制摄像头拍照）即可。<br />
下面是程序，用shell脚本就可以实现了，超简单：</p>
<section class="output_wrapper" id="output_wrapper_id" style="font-size: 16px; color: rgb(62, 62, 62); line-height: 1.6; letter-spacing: 0px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">
<pre style="font-size: inherit; color: inherit; line-height: inherit; margin-top: 0px; margin-bottom: 0px; padding: 0px;">
<code class="bash language-bash hljs" style="margin: 0px 2px; line-height: 18px; font-size: 14px; letter-spacing: 0px; font-family: Consolas, Inconsolata, Courier, monospace; border-radius: 0px; color: rgb(169, 183, 198); background: rgb(40, 43, 46); padding: 0.5em; overflow-wrap: normal !important; word-break: normal !important; overflow: auto !important; display: -webkit-box !important;"><span class="hljs-meta" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(91, 218, 237); word-wrap: inherit !important; word-break: inherit !important;">#!/bin/bash
</span>
<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">#&nbsp;A&nbsp;touch-switch&nbsp;control&nbsp;program.

</span>

<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">#&nbsp;the&nbsp;Raspberry&nbsp;Pi&nbsp;GPIO&nbsp;input&nbsp;pin&nbsp;number,&nbsp;namely&nbsp;the&nbsp;pin&nbsp;connected&nbsp;to&nbsp;the&nbsp;signal&nbsp;output&nbsp;pin&nbsp;of&nbsp;the&nbsp;toch-switch&nbsp;module&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
GPIO_PORT=8

<span class="hljs-comment" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(128, 128, 128); word-wrap: inherit !important; word-break: inherit !important;">#&nbsp;set&nbsp;the&nbsp;specified&nbsp;GPIO&nbsp;port&nbsp;to&nbsp;INPUT&nbsp;mode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
gpio&nbsp;mode&nbsp;<span class="hljs-variable" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(98, 151, 85); word-wrap: inherit !important; word-break: inherit !important;">$GPIO_PORT</span>&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">in</span>

<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">while</span>&nbsp;<span class="hljs-literal" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(174, 135, 250); word-wrap: inherit !important; word-break: inherit !important;">true</span>
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">do</span>
&nbsp;&nbsp;&nbsp;&nbsp;SWITCH_STATUS=`gpio&nbsp;<span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">read</span>&nbsp;<span class="hljs-variable" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(98, 151, 85); word-wrap: inherit !important; word-break: inherit !important;">$GPIO_PORT</span>`
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">if</span>&nbsp;[&nbsp;<span class="hljs-variable" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(98, 151, 85); word-wrap: inherit !important; word-break: inherit !important;">$SWITCH_STATUS</span>&nbsp;-eq&nbsp;1&nbsp;];&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">then</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-built_in" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">echo</span>&nbsp;<span class="hljs-string" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(238, 220, 112); word-wrap: inherit !important; word-break: inherit !important;">&quot;Pressed&nbsp;@&nbsp;`date&nbsp;+\&quot;%F&nbsp;%T\&quot;`&quot;</span>
&nbsp;&nbsp;&nbsp;&nbsp;<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">fi</span>
&nbsp;&nbsp;&nbsp;&nbsp;sleep&nbsp;0.01
<span class="hljs-keyword" style="font-size: inherit; line-height: inherit; margin: 0px; padding: 0px; color: rgb(248, 35, 117); word-wrap: inherit !important; word-break: inherit !important;">done</span></code></pre>
</section>
<p>程序也可以在我的<a href="https://github.com/codelast/raspberry-pi/tree/master/gpio/touch-switch" rel="noopener noreferrer" target="_blank"><span style="background-color:#ffa07a;">GitHub</span></a>上找到。<br />
那么，这么简单的一个小东西，有什么用呢？我们可以把我们经常需要树莓派做（但又没有固定周期）的一些任务，用这个触摸开关来控制，例如可以在摸它一下的时候，调用pacman -Syu来升级Arch Linux ARM。还可以怎么玩，全凭你的想像力了。</p>
<p><span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
感谢关注我的微信公众号（微信扫一扫）：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
	<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="width: 200px; height: 200px;" /></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e6%a0%91%e8%8e%93%e6%b4%be%e4%b8%8a%e4%bd%bf%e7%94%a8%e8%a7%a6%e6%91%b8%e5%bc%80%e5%85%b3%ef%bc%88touch-switch%ef%bc%89/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
