<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Micropython Counter]]></title><description><![CDATA[<p dir="auto">I am trying to increment counter by 1 whenever a button is pressed. to this end I have come up with this code:</p>
<p dir="auto">import time<br />
import machine<br />
from machine import Pin</p>
<p dir="auto">tip_num = 0<br />
tip = (Pin('P10', <a href="http://mode=Pin.IN" target="_blank" rel="noopener noreferrer nofollow">mode=Pin.IN</a>, pull=Pin.PULL_UP))<br />
tip([1])</p>
<p dir="auto">while tip  !=&quot;&quot;:<br />
tip_num += 1<br />
tip_value = (tip)<br />
total += tip_value<br />
tip = (Pin('P10', <a href="http://mode=Pin.IN" target="_blank" rel="noopener noreferrer nofollow">mode=Pin.IN</a>, pull=Pin.PULL_UP))</p>
<p dir="auto">print(&quot;Counter&quot;, tip_num)<br />
print(&quot;Done&quot;)</p>
<p dir="auto">I have clearly missed something but I have no idea what it is?<br />
Any help would be GREATLY welcomed.</p>
]]></description><link>https://forum.pycom.io/topic/3463/micropython-counter</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 19:07:45 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/3463.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 10 Jul 2018 16:15:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Micropython Counter on Tue, 10 Jul 2018 16:15:16 GMT]]></title><description><![CDATA[<p dir="auto">I am trying to increment counter by 1 whenever a button is pressed. to this end I have come up with this code:</p>
<p dir="auto">import time<br />
import machine<br />
from machine import Pin</p>
<p dir="auto">tip_num = 0<br />
tip = (Pin('P10', <a href="http://mode=Pin.IN" target="_blank" rel="noopener noreferrer nofollow">mode=Pin.IN</a>, pull=Pin.PULL_UP))<br />
tip([1])</p>
<p dir="auto">while tip  !=&quot;&quot;:<br />
tip_num += 1<br />
tip_value = (tip)<br />
total += tip_value<br />
tip = (Pin('P10', <a href="http://mode=Pin.IN" target="_blank" rel="noopener noreferrer nofollow">mode=Pin.IN</a>, pull=Pin.PULL_UP))</p>
<p dir="auto">print(&quot;Counter&quot;, tip_num)<br />
print(&quot;Done&quot;)</p>
<p dir="auto">I have clearly missed something but I have no idea what it is?<br />
Any help would be GREATLY welcomed.</p>
]]></description><link>https://forum.pycom.io/post/20752</link><guid isPermaLink="true">https://forum.pycom.io/post/20752</guid><dc:creator><![CDATA[Justin_Dylan]]></dc:creator><pubDate>Tue, 10 Jul 2018 16:15:16 GMT</pubDate></item><item><title><![CDATA[Reply to Micropython Counter on Wed, 11 Jul 2018 15:01:54 GMT]]></title><description><![CDATA[<p dir="auto">Python code without proper indentation is not very useful. You should try to put it inside a code block like this:</p>
<pre><code>import time
import machine
from machine import Pin

tip_num = 0
tip = (Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP))
tip([1])

while tip !=&quot;&quot;:
  tip_num += 1
  tip_value = (tip)
  total += tip_value
  tip = (Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP))

print(&quot;Counter&quot;, tip_num)
print(&quot;Done&quot;)
</code></pre>
<p dir="auto">Apart from that there are a lot of mistakes (e.g. <code>tip([1])</code>) and redundancies (e.g. wrapping everything in parenthesis) in your code. You should probably read the the <a href="https://docs.pycom.io/chapter/gettingstarted/programming/examples.html" target="_blank" rel="noopener noreferrer nofollow">MicroPython</a> and <a href="https://docs.pycom.io/chapter/firmwareapi/pycom/machine/Pin.html" target="_blank" rel="noopener noreferrer nofollow">Pin</a> documentation first.</p>
]]></description><link>https://forum.pycom.io/post/20779</link><guid isPermaLink="true">https://forum.pycom.io/post/20779</guid><dc:creator><![CDATA[Sympatron]]></dc:creator><pubDate>Wed, 11 Jul 2018 15:01:54 GMT</pubDate></item></channel></rss>