Micropython Counter
-
I am trying to increment counter by 1 whenever a button is pressed. to this end I have come up with this code:
import time
import machine
from machine import Pintip_num = 0
tip = (Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP))
tip([1])while tip !="":
tip_num += 1
tip_value = (tip)
total += tip_value
tip = (Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP))print("Counter", tip_num)
print("Done")I have clearly missed something but I have no idea what it is?
Any help would be GREATLY welcomed. -
Python code without proper indentation is not very useful. You should try to put it inside a code block like this:
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 !="": tip_num += 1 tip_value = (tip) total += tip_value tip = (Pin('P10', mode=Pin.IN, pull=Pin.PULL_UP)) print("Counter", tip_num) print("Done")Apart from that there are a lot of mistakes (e.g.
tip([1])) and redundancies (e.g. wrapping everything in parenthesis) in your code. You should probably read the the MicroPython and Pin documentation first.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login