Arduino Coding Issue...figured I'd ask my peer here first

Yes.. the code does what you requested..... and if thats all you ever need it to do.. then you should be fine.
There are also some variables at the top you can use to play around with..

* and you can keep the same hardware setup.. your just using an external pull-up resistor.. (even though the internal one is being set in the code).. :)
 
Right. But eventually with other Arduinos I want to do a total of three chasing light patterns randomized for how long they run for the Pegasus UFO. Other models will mostly just have torp launches or weapon fires or maybe some powering up and powering down sequences. I'm dazzled by possibilities and daunted by the coding.
 
Just dropping in here a bit late. The best thing I ever learned to do was use a "state machine". All a state machine is looping code that does short tasks when needed. When you use a state machine you virtually have a multi-tasking processor.
Here is some good tutorial code: j-bellavance/Tutorials

How a state machine works is you basically set up variable that tell the processor what state your code is in. For example, you might have a state which is: "Idle, waiting for button press". Or one which is: "Fade the LED". Your main loop then just has if > then sort of code that does only certain tasks when the state is actually called for. This allows you to say check the status of the button every loop, but also still fade, pulse the LED without delaying the next button detection.

A state machine helps you from getting stuck into looping code which does only one thing at a time. By using one I have been able to make some very complex things that work well, and are easier to debug. (as your debugging just one sub-routine instead of all your code)
 
Here is something "I" would consider a more advanced state machine project..

Not only state machine approach.. but all LED animations/patterns are built to be NON-BLOCKING. (ie: you are never stuck in a loop, the pattern animations are incremented loop by loop (per 'pass')

While it make not SEEM like much.. its not always the easiest to write code that 'does several things at once'*:

Its a custom tail light with integrated blinkers I am working on for a buddies motorcycle..

Using only 1 strip of Neopixels: (probably should have used DotStars...but I dont have much else going on besides the led patterns, so it works fine)

* just the firmware/code stage:

Normal:

Scrolling blinkers:

So while the blinkers are blinking, or scrolling.. you can still control the brake.. (meaning detection of the brake button being pressed, -and- controlling the other leds in the strip)

This would be an IMPOSSIBLE project if you tried to approach using the same type of approach above (delays, and blocking loops)..etc
 
Just dropping in here a bit late. The best thing I ever learned to do was use a "state machine". All a state machine is looping code that does short tasks when needed. When you use a state machine you virtually have a multi-tasking processor.
Here is some good tutorial code: j-bellavance/Tutorials

How a state machine works is you basically set up variable that tell the processor what state your code is in. For example, you might have a state which is: "Idle, waiting for button press". Or one which is: "Fade the LED". Your main loop then just has if > then sort of code that does only certain tasks when the state is actually called for. This allows you to say check the status of the button every loop, but also still fade, pulse the LED without delaying the next button detection.

A state machine helps you from getting stuck into looping code which does only one thing at a time. By using one I have been able to make some very complex things that work well, and are easier to debug. (as your debugging just one sub-routine instead of all your code)
My head hurts just reading this code you posted...I am a BAD coder lol
 
Here is something "I" would consider a more advanced state machine project..

Not only state machine approach.. but all LED animations/patterns are built to be NON-BLOCKING. (ie: you are never stuck in a loop, the pattern animations are incremented loop by loop (per 'pass')

While it make not SEEM like much.. its not always the easiest to write code that 'does several things at once'*:

Its a custom tail light with integrated blinkers I am working on for a buddies motorcycle..

Using only 1 strip of Neopixels: (probably should have used DotStars...but I dont have much else going on besides the led patterns, so it works fine)

* just the firmware/code stage:

Normal:

Scrolling blinkers:

So while the blinkers are blinking, or scrolling.. you can still control the brake.. (meaning detection of the brake button being pressed, -and- controlling the other leds in the strip)

This would be an IMPOSSIBLE project if you tried to approach using the same type of approach above (delays, and blocking loops)..etc
O_O Beyond me....even to fathom the code is like an ant trying to understand Go Dog, GO
 
But to boil things down to what I'm looking to do with all my models, each period denotes a different button press or action
PL Rom BoP = Just light up...done. Needs primed and painted. Got it together before I had the Arduino ideas for everything and not just the UFO. interior and nacelles are wired together so it could maybe get like a flickering damage code to a button.
PL Enterprise = I don't have it but if I get it, maybe a simple torp sequence with a small blue fiber dot. Nacelles will light of course, plus I can use some 1.8mm for the running lights on the side of the saucer.

The above models I want to put together for a Balance of Terror kind of thing. Base will most likely be a fiber optic star field. I can see it now (dreaming)

PL Klingon D7 = Torp fire (coded thanks to xl97). Flickering engine (done with special LEDs)
AMT K'T'inga = Torp fire. Startup power up (fade up lights to stay on). Aft Torp Fire. Disrupter random fire. Flickering engines (Special LEDs again). Blinking red running lights (I have blinking red LEDs, a blinker PCB or I can do this with Arduino too)
AMT Klingon Bird of Prey = Torp Fire, Disrupter random firing, Flickering engines (LED specials)
AMT Enterprise Refit = It's pre lit but that lighting is dated and ugh. So..I've seen code: Startup Sequence from TMP, Fire Torps (button will fire 1 tube, then fire the other), Phaser fire.
AMT Romulan Warbird = Power up sequence with one press, power down on other. Ramp up nacelles to warp flash. Torp fire. Disrupter Fire.
Pegasus UFO = Here is where it gets complicated. Six green LEDS to chase one direction, chase the other direction, blink all six then 1,3,5 and 2,4,6. All randomized time so it will swap from one pattern to the other at random for random time intervals. (figuring out that code will be the ultimate achievement)
AMT Romulan Bird of Prey = Probably something similar to the Enterprise Refit. A start up sequence. Plasma torp fire, and possible a damage button (causing random fades and flickers to the nacelle lights and interior.

Can it be done? Probably. Can it be done by me? 25% chance at best assuming I find code examples and tweaks. My biggest fears are needing PCBs and controller chips. Opinions on all of this and difficulty? Again nothing is really built and permanently wired just yet except the first model.
 
The issue is twofold: I have a comprehension problem with code. I can read it and understand it for the most part. But I can't write for ****. The longer I look at it, the more my head hurts. Even just tweaking the code I was given by xl97 for my purposes caused me to wake up with a migraine. I don't know if its a mental block or a real disability.
 
Just the 'unknown' (so stress/pressure)..

But thats why its called 'learning'.. you cant know it all.

Sometimes it takes submerging yourself into things so the naming conventions and terminology start to make sense, then the suggestions and code people offer start to make sense.. etc...etc... (its a domino effect)..

In the end, it will be up to you and your determination and motivation on you are comfortable taking on.
 
Just the 'unknown' (so stress/pressure)..

But thats why its called 'learning'.. you cant know it all.

Sometimes it takes submerging yourself into things so the naming conventions and terminology start to make sense, then the suggestions and code people offer start to make sense.. etc...etc... (its a domino effect)..

In the end, it will be up to you and your determination and motivation on you are comfortable taking on.
I just keep remembering coding in college and staring at the screen for hours wondering why I could never get much past "Hello World"
 
I don't think I can code anymore. Even though it's working like I want exactly...the migraines it's giving me are hideous.
 
The issue is twofold: I have a comprehension problem with code. I can read it and understand it for the most part. But I can't write for ****...

This is exactly my problem! I took a few coding classes, and I could always read it and follow along. But given a blank page, NO IDEA where to even start. That’s why most of my coding has been repurposing existing code that I’ve found.

Sean
 
As long as its free for use... no problem in that.

Whatever gets your prop/project to the next level!

I have always found it easier to learn, when I have an end goal in mind.

So the things I learn, arent just 'random facts'... but actually understand not only HOW, but when and why I use those approaches/techniques.


IE: Learning about Arrays or For loops might 'stick better' if they are used for a purpose you understand/see valid.

IMHO.. beginner Arduino stuff is for 'every one' .. even if you dont really understand coding.

Thats its purpose. To bridge the electronics realm/gap to those who arent pros/professionally trained to be an EE's.

You can do A LOT with very LITTLE knowledge.
 
As long as its free for use... no problem in that.

Whatever gets your prop/project to the next level!

I have always found it easier to learn, when I have an end goal in mind.

So the things I learn, arent just 'random facts'... but actually understand not only HOW, but when and why I use those approaches/techniques.


IE: Learning about Arrays or For loops might 'stick better' if they are used for a purpose you understand/see valid.

IMHO.. beginner Arduino stuff is for 'every one' .. even if you dont really understand coding.

Thats its purpose. To bridge the electronics realm/gap to those who arent pros/professionally trained to be an EE's.

You can do A LOT with very LITTLE knowledge.

Words from a very wise man.....(y)It's hard to "cut and paste" your way thought life.
 
Oh it's far from done. I need more Arduinos, screw shields and it's looking like shift registers with external power outside of the Arduino. My larger models will have more than just 8 LEDs. Hell my polar lights d-7 has 7 packed into it's tiny body. The K'tinga and Enterprise are going to be far far more.
 
TIP/SUGGESTION:

As they are easy to use, and what I would consider a 'beginner' step in branching out to control more LEDS.

Look into using a MAX7219 chip. It take very little passive components to connect to an Arduino, and can control up to 64 leds. And the MAX chips can be daisy chained together as well.. so thats another 64 leds per MAX chip you add.

Of course this all depends on what you want to do with them..

Those or 'Neopixels' (if you can provide enough current) can usually solve most low powered LED projects now a days. (IMO at least)

You can use an Arduino UNO..

or a Nano or a Pro-Mini (smaller and smaller footprint on these boards) to fit in your smaller props.

There are so many variants on 'Arduino compatible boards'.. that you can usually find one in a size and/or extra feature if you need something specialized.
 
Uno is the name of the game and all electronics are going to be in the base which is an 8x10x1 acrylic box frame that would normally hold photos.
 
How does one use the max chip? Do I need a pcb for it?

Edit: it looks like it controls an 8x8 matrix. That won't work. The LEDs are all in different places in the models and I need more than 8 individual ones on at a time and then controllable too
 
This thread is more than 3 years old.

Your message may be considered spam for the following reasons:

  1. This thread hasn't been active in some time. A new post in this thread might not contribute constructively to this discussion after so long.
If you wish to reply despite these issues, check the box below before replying.
Be aware that malicious compliance may result in more severe penalties.
Back
Top