Why does the state of a "momentary button" alternate?

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
himoh82538
 
Posts: 3
Joined: Fri May 28, 2021 11:45 pm

Why does the state of a "momentary button" alternate?

Post by himoh82538 »

Basically, I just need a way to tell the microcontroller "to do something" over the Internet. Before that, I was telling it using a physical push button, and I was using digitalRead returned LOW when pressed, and HIGH when released (the example I had followed worked like that, so I copied that. I am not sure if this could be the other way around).

Now, I looked at the list of "Blocks" and the "Momentary Button" seemed to be the closed one for what I want to do. I just need a "clicked" event, but the "Momentary Button" seems to be generating two events, HIGH and LOW, for one mouse click. And by default, pressed was HIGH and released was LOW. That was the opposite of the physical push button, and it was confusing, so in the Block settings, I set the "Press Value" to "0" and the "Release Value" to "1", so that pressed would be LOW(0).

But there it works in a weird way. I had expected that the order would always be LOW(0, clicked) and then HIGH(1, released); that is, always returning to the released state (1). But in reality, the order keeps alternating, so the last value is sometimes 0 and sometimes 1, as you see below in the screen captures. What gives?
damn.PNG
damn.PNG (36.05 KiB) Viewed 355 times
Attachments
damn2.png
damn2.png (27.49 KiB) Viewed 355 times

User avatar
himoh82538
 
Posts: 3
Joined: Fri May 28, 2021 11:45 pm

Re: Why does the state of a "momentary button" alternate?

Post by himoh82538 »

PS: I am not sure, but after some more testing, it seems that it only (or mostly) happens when I tap the button with a finger on an Android phone. If I click the button with a mouse on Windows, it does not seem to happen (I could not test a lot because of the throttling for the free version).

User avatar
brubell
Learn User Page
 
Posts: 2010
Joined: Fri Jul 17, 2015 10:33 pm

Re: Why does the state of a "momentary button" alternate?

Post by brubell »

This might be an issue with the Android browser - could you try adding a switch block instead of a momentary button? It'll should retain state.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”