i want to build a simple program that do this:
when i push button led is on when i release the button led is off
i want to build a simple program that do this:
when i push button led is on when i release the button led is off
Try an âifâ statement in your loop, combined with a digital read. Should work.
can u give me example of digital read please
I could. But seeing as this is the most basic thing you can do, I would HIGHLY reccomend following/reading some tutorials on arduino for example (they are very much alike). If you donât manage this, thereâs an increased risk of damaging things if you mess up, which would be a shame.
I donât mean to be harsh or anything, but be sure to read op on things, and start of easy, for your own good.
Examples of all the functions can be found on the documentation pages. docs.spark.io at the âfirmwareâ section, including the digital read function.
Donât hesitate to ask if you feel like you need help, but definitely read up on some or the basic arduino stuff. Itâll make thing a lot easier for you!
Best of luck!
Like @Moors7 mentioned, doing that is fairly simple:
Within setup()
attach your interrupt function to FALLING or RISING event. This depends on how you design your circuit.
Within your interrupt function, do only simple things as fast as possible, like switching a boolean variable from false to true (like turning on and off).
Write another function with a condition based on that variable to turn the LED on/off and call that from inside loop()
This forum is pretty helpful and quick to respond, but itâs helpful to read up on simple arduino docs and paste your code here when you have hit a problem.
Thatâs the neat way of doing it.
The âhello worldâ, stupidly simple, version would be something along the lines of:
if (digitalRead(pin) == HIGH){
digitalWrite(led, HIGH);
}
else{
digitalWrite(led, LOW);
}
Which is the equivalent of:
if (pushed){
LED on
}
else{
LED off
}
That certainly isnât the preferred way of doing it, but it should somewhat work. Itâll at least teach you the workings of the Read/Write functions.