Button to LED code

can you help me guys, i need to program the button that when pressed and hold for 3 seconds it will light up the LED and also, can it be that it will automatically turned off for such a given time? i found this image and maybe somehow the circuit board is like this?

I could be mistaken, but I believe you asked the exact same question already: https://community.spark.io/t/spark-core-button-to-led/5979

I’ll try again: [quote=“Moors7, post:2, topic:5979, full:true”]
Did a quick google, and found this to be helpful: https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-5/recipe-5-4You should be able to easily edit that to count the time your button is pressed (5 secs) and make it do something.

To use the onboard LED, assign it to pin D7.

Good luck!

The code which I linked to really isn’t that hard, there’s even an explanation. If you want to have any success in building projects like that, you should be able to read code like this, and edit it accordingly. Giving you the complete code would be easier for you, but then you wouldn’t learn anything. If, in the future, you want to do something else with it, you wouldn’t know how it works.
The fun in working with the Spark lies in the fact that you learn a lot of stuff in the progress. If you can’t understand this code, I suggest you start of easier, a blinking LED perhaps. From there on, build your way up, going progressively more difficult. You’ll notice that it’s much more rewarding if you can pull projects like this off yourself, instead of it being handed to you by one of us.

I’m not sure about the schematic, although for prototyping, you could use the built-in LED that’s connected to pin D7. If you do a digitalWrite(D7, HIGH), then the blue LED should light up.
The button seems to be okay, but it could be that you don’t need the resistor, since the Spark operates on 3.3V, but I could be mistaken on that one.

Since you’ve asked the same question twice, I’d like to clear some things up;
Do you want us to help you, like you say at the beginning?

Or do you want us to hand you the working code?

Neither one should be a problems, but it’d prevent you from creating a third topic in the hopes of getting the working code :wink:

Either way, good luck!

sorry but im just new to spark core, i dont know how to operate the button one, ive already done the annotated examples in docs. i can read the program the problem is the spark core is ive said new to me

@paolosofio01, let’s rewind a bit. How much experience with Arduino or any other micro-controller do you have?

i just have experience in school in one subject for a year (8051 mc) arduino, not yet, but programming yes i can read and code but it takes a while because i need to learn it first

The Spark is very much like the arduino, just a different layout, and some awesome extras (connectivity for example). If you can work with an arduino, you can also work with the Spark. I’m a newbie myself, having never even worked with an arduino, nor do I have any programming knowledge. Personally I liked starting of easy, like the blinking LED. It gave me the basic idea of how the functions work. From there on I expanded, making it increasingly more difficult. In the case of the Spark it’s really nice that you can also follow arduino tutorials because the two have a lot of similarities. That’s why I’d suggest if you’re unsure about your capabilities with either the programming, or the link between programming and “what does this do on my board”; Follow some tutorials for arduino, of just watch some tutorial videos. You don’t have to actually build everything, as long as you can follow along with what they’re saying, and you can reasonably understand what they do. It’s been really helpful to me, as well as the help of this awesome community :)!

Saying you understand the code, I guess the issue would be the hardware? Or perhaps the code in combination with the Spark (pin assignment etc)?
If you could tell us the exact problems you’re having, we could offer more precise help.

(@peekay123, could you perhaps delete/merge his other topic, to prevent duplicate threads? I don’t have the rights to do that (yet… :smiling_imp:))

@paolosofio01, have you considered getting an Arduino to get familiar with the examples you are trying to learn? Trying to get Arduino examples working on the Spark is not always straight forward for a beginner. My concern is if you are trying to learn how to do a button, learning wifi and cloud stuff may be too much of a leap to begin with. Any thoughts?

@Moors7, there was nothing on the other topic that you did not already mention so I deleted it.

I’m not sure, I personally never had an Arduino, and I seem to be doing OK-ish. Didn’t have programming experience either, other than a tiny bit of HTML/CSS.
What I think is really important is that you do a lot of reading. Not so much books and stuff, but code examples. Try to figure out what the code is doing, step by step. Then try to find a single function of code and make it work by commenting out other parts, while making sure that “your part” still works. That’ll get you to understand the code better, and it helps you to look out for important stuff. You can’t get an LED to blink if you don’t initiate its pin first, for example.
If you can get that function working, try to expand on it. Try editing parts of it, and see what it does. Just “tinker” around a bit. Playing is the best way of learning I think. See what the code does, and then try to figure out why it does just that. But start of simple, don’t try to make a TwitterTorch for your very first project, even though it’s awesome. It might look really cool, but you’ll have no idea why it’s doing what it’s doing, thus learning nothing in the process.
The nice thing about the Spark is that the WiFi/connection part is there, but you don’t HAVE to use it. You can do Arduino stuff on the Spark as well. Once you’ve got that (reasonably) under control, you could try out some of the connected projects. Even better is that you don’t have to worry about all the technical know-how of the connection. To put it in Apple terms:“it just works”. It’s somewhere on the background, but as soon as you need it, it’s there. The same thing applies here: start of simple, don’t make things harder than they need to be.
Like the “blink an LED from the web”, try to edit the complementary code to make it do something else, other than blinking an LED, and expand from there. I think this is really helpful when starting, so you don’t have to worry about the CURL stuff: http://community.spark.io/t/spark-core-web-interface-works-on-desktop-mobile/5908

Then again, the cheapest Arduino Uno R3 (clone?) on Ebay is around $7 incl. shipping, so you can’t really go wrong on that… Personally I wanted to start with the awesome stuff, not some boring old unconnected thingy :wink: If I’ve got to learn it, might as well do it properly. It’s only going to get more connected from here on, so might as well make the best of it!

Thanks for deleting, I can only edit topic titles :cry:


hey guys sorry, im doing this for my thesis project and i guess we dont have much time to get another arduino to make us familiar with spark, i did look on the documentation and its a little bit confusing.