Example of input type button in html?

Second project. I wanted to play with it a little bit and wanted to use button as input type instead of radio. The parameters are different so I tried:

<input type="button" onclick="functionCall('ledToggle', 'on')" value="Toggle LED">

But don’t know how to actually use it, yes, It didn’t work. But let’s not actually discuss that. Can someone give me an example to toggle pin D0 from the browser with button inputs? It’s not that I’m a newbie in HTML and JS (Nor above average). It’s the parameters.

That looks an awful lot like some code I once wrote, which was intended to be used with the JavaScript library, which is also why that doesn’t work. There’s no ‘magic Particle parameter’. That ‘onclick’ simply calls a Javascript function which in turn makes the request.
This guide discusses how to call the API directly, and has an example of what you’re looking for:

1 Like

Sorry, I really can’t wrap my head around that. I’m no newbie at javascript nor average. Is there maybe a documentation about that especially for particle?

Thanks for the reply

The above is especially for Particle, and does the very thing you’re asking for. Unless you can formulate your question more accurately, I’m not sure what else it is you’re looking for.

1 Like

Well it doesn’t actually help very much. It’s too complicated for my js knowledge.

In that case, you might want to be more careful when saying things like…


That might set (evidently) incorrect expectations, which is much rather avoided.

In all honesty though, I’m not sure that that tutorial can be made much simpler. You’ve got a button, and when you click it (or change the value), it executes a function. In that function you make a call to the REST API that triggers your function on the device.
Then there’s a polling thing going on where it checks a variable at a set interval and updates the corresponding boxes.

What exactly do you have troubles with understanding, perhaps we can clarify that? Alternatively, copy the code, and try reducing it to a bare minimum: single button, blink an LED :slight_smile: Just try to see what happens when you change something.

1 Like