Welcome, %1$s. Please login or register. - Did you miss your activation email?

Login with username, password and session length
 

Author Topic: Some basics  (Read 295 times)

Offline scottminium

  • Admiral
  • *****
  • Posts: 846
  • "Not chess, Mr. Spock. Poker!"
Some basics
« on: June 02, 2017, 02:39:07 pm »
Hello all! 

I've been reading a number of these threads today as I contemplate taking the jump into Arduino for some upcoming kits.  I really appreciate all the code examples, which would make jump starting pretty easy.

I've got plenty of questions (some related to how the coding works) but I'll start with a couple simple ones:

Let's say I turn on power to the Arduino.  Most of the lights will then be on, or blinking at various rates.  How would I physically wire in a switch that would allow 'firing' a set of lights a predetermined number of times (not on forever)?

Do you need a reset switch when you first power up an Arduino or does it just start running the program?

Thanks for your patience and help!
"If there's a bright center to the universe, you're on the planet that it's farthest from."

Offline simi

  • Admiral
  • *****
  • Posts: 586
  • JUST enough knowledge to do some serious damage
Re: Some basics
« Reply #1 on: June 02, 2017, 06:31:10 pm »
Scottminium,

Not sure I entirely understand your question - but here's what I generally do.  I usually have a button (a switch) which turns on the power to the arduino.  That way, the arduino isn't constantly "on" when I don't really want it to be on and doing anythin.  Though it doesn't really draw all that much power if it's left on all the time. 

When you supply power to the arduino - it simply "boots up" and starts running the code automatically - whatever you coded it to do.  In some cases, your code may say "hey, when I'm on - turn on the lighting effect".  Or, in the description below, it starts "listening" to external events.  Of course, you can also have it do both.

Anyhow, you can wire another switch or momentary switch to one of the arduino pins as an input.  The arduino "listens" to that pin, and when you press the button - your code will trigger whatever event(s) you want.  Run your lights, trigger sounds, etc.  You can also code things in such a way (with a momentary switch) that a single button can toggle multiple effects.  For example, on one of my kits I have the "power" switch that turns the Arduino on.  Arduino has to have power to do anything :) Now that it's on, it's listening for a button push.  When I press that button (a momentary switch), it starts the static lighting.  When I press that same button again, the arduino starts the strobe/beacon lights along with the static lighting.  When I press it a third time, it turns both effects off.  Press again, and it starts over with starting the static lighting, etc.

This is probably only helpful in understanding "what" you might want/be able to do - but not too helpful on step-by-step instructions.  But once you understand and have a couple of code example of this - it will make A LOT more sense if it doesn't already.

So, again, how would LIKE your (assuming it's lighting things) kit lighted and how would you like things to be triggered?  Power on, turn everything on?  Power on, some things turn on and some wait for other button inputs, etc.

Sorry for rambling, but once you get the very basics down - it's really fun to get some cool effects and have them timed exactly how you want them and such.  Keep playing around and asking questions.  Tons of stuff on the 'net about arduinos and basic lighting/control mechanisms. 

Cheers!

Simi




As a software architect, I'm pretty darn good.  As someone with knowledge of building things in the real world, well, I'm a software architect.

Offline scottminium

  • Admiral
  • *****
  • Posts: 846
  • "Not chess, Mr. Spock. Poker!"
Re: Some basics
« Reply #2 on: June 03, 2017, 07:12:45 am »
Simi, you correctly deduced what I was trying to get at.  Please let me continue on the topic of the "push button for effect."  That is the switch I want to understand how to wire up.

Following your other instructions, after some sleep I used google-foo to search on 'arduino switch input.'  I found a good code example on the arduino page.  That example simply switches the output from LOW to HIGH based on the push, so I gather I would just add my 'torpedo firing sequence' there instead of just switching it on.

I also found this diagram of how to wire the switch.  Using the 5V regulated output for the power supply, why is the 1K (or the 10K) resistor needed?  I gather the 1K is just to drop the input pin voltage to near zero since a full 5V is not needed to get an 'on' reading.
Thanks again!

Scott
"If there's a bright center to the universe, you're on the planet that it's farthest from."

Offline simi

  • Admiral
  • *****
  • Posts: 586
  • JUST enough knowledge to do some serious damage
Re: Some basics
« Reply #3 on: June 03, 2017, 10:35:36 am »
I would recommend the arduino site for most of your queries.  It has the code and layouts for some of the very things you're asking about.  For example, here's the tutorial to turn on a single LED by a button:

https://www.arduino.cc/en/Tutorial/Button

Your not trying to turn on a single LED, but where the code is turning on the LED in the example is where you would change the code to trigger your effects.

Also, might want to look at the followup example if you're using a momentary switch. Each tutorial is only about a page or so long and comes with the schematic and the code.

https://www.arduino.cc/en/Tutorial/Debounce


BTW, if I recall - the IDE for the arduino comes with all these code examples already installed - so kinda nice for playing around.

Cheers!

Simi
As a software architect, I'm pretty darn good.  As someone with knowledge of building things in the real world, well, I'm a software architect.

Offline scottminium

  • Admiral
  • *****
  • Posts: 846
  • "Not chess, Mr. Spock. Poker!"
Re: Some basics
« Reply #4 on: June 03, 2017, 07:20:31 pm »
Thanks!  As a software architect you're...well, you know.
"If there's a bright center to the universe, you're on the planet that it's farthest from."

Offline MarkW

  • Plastic Surgeon
  • Admiral
  • *****
  • Posts: 1334
    • MW ModelWerks
Re: Some basics
« Reply #5 on: June 11, 2017, 06:40:11 am »
If you want to do a rotating reaction based upon a button press, one function you should look at is modulo.  It returns the remainder of the division, so you can bound the number that is returned by your starting point. For example, seven modulo four returns three, the remainder of 7
MarkW
"I can cross stab Hitler to death off the list of cool crap I thought I'd never do"
--Brock Sampson
NEW WEB ADDRESS

 




Enterprise © Bloc