I’m trying to count button click but only after 5 clicks and after the fifth click it will print the clicks BUT starting at 1.
JavaScript
x
9
1
Example:
2
Press button = 1 click
3
Press button = 2 click
4
Press button = 3 click
5
Press button = 4 click
6
Press button = 5 click
7
Press button = "ROUND: 1"
8
Press button = "ROUND: 2" ..etc.
9
I have the function below and when button_clicks() is called it displays and counts a 6,7,8 etc. instead 1,2,3 etc.
JavaScript
1
9
1
clicks = 0
2
3
def button_clicks():
4
global clicks
5
clicks += 1
6
if (clicks) > 5:
7
lcd.move_to(0,3) #Moves text 0 characters from left on row 4
8
lcd.putstr("ROUND: " + str(clicks))
9
I also needed to add another two buttons B3 and B4 that would decrease or increase the number by 1. How would I do that?
Advertisement
Answer
I figured it out…. But still need a button to increase and a button to decrease the value.
JavaScript
1
10
10
1
def button_clicks():
2
global clicks
3
clicks += 1
4
if (clicks) > 5:
5
lcd.move_to(0,3) #Moves text 0 characters from left on row 4
6
lcd.putstr('Rnds: {}'.format(clicks-5))
7
else:
8
lcd.move_to(0,3) #Moves text 0 characters from left on row 4
9
lcd.putstr('Rnds: -{}'.format(clicks))
10