Hey gang-
I think the other/original thread has proven this was a OUT OF RAM problem.. and not really a logic problem in the sketch..
Disclaimer:
I have coded things the best I know/thought was the best way.. (so if you ask "WHY" I didnt something this way or that.. its because I didnt know any better and didnt what worked or what I thought was best practice)
Summary:
Stage prop/project, Sci-FI blaster
Arduino, WaveShield, 2 x MAX7219 chips (led bargraph & 3-digit 7-segment display)
Problem:
Things are/were working as I believe they should...
when adding in NEW/MORE code, I got odd behavior... Code/routines/functions that previously worked, stopped/or acted oddly, .. even though the newly added code/snippets didnt even pertain to the portions that stopped working..
After some clean-up, and the addition of using the F() macro for string literals/Serial.print() stuff...
I got more "FREE RAM" back.. and the newly added code snippets started working. Leading me to believe its a RAM issue, and setting out to learn more/discuss ways I can improve this sketch of mine.
I am not very experienced in coding in C/C++ (for Arduino).. so I doubt VERY advanced stuff will work (direct port manipulation and other very advanced approaches may be wasted here?)
However I am open to discussing anything.
As of now..
the only external libs I am importing are:
#include "LedControl.h"
#include "WaveUtil.h"
#include "WaveHC.h"
*the WaveHC/Util libs are for the audio playback...
*the ledControl lib is for working with the MAX7219 chip(s). 1 for the 3-digit/7-segment display.. and 1 for the 30 x SMD 1206 LED bargraph
Being as I have never run into this type of problem before (running out of RAM)...
I want to be clear on the difference of
SKETCH size.. (32kb of space for this)
vs
2K of RAM..
when uploading.. my sketch size says Im under HALF (around 12-13000+ bytes out of 32256 max)..
yet when I upload things.. and have the freeRAM() function spit out the data... Im only (at best) around 195 left! YIKES!!!
I'd like to get suggestions & help on some BASIC tricks/tips people can do to optimize? (or if there is a link/article/tutorial somewhere)...
I'd also like to discuss any more advanced suggestions as well.
here are some random thoughts I had, but not sure how relevant they are)
1.) removing some of the functions in the sketch? good for only sketch size? or help reduce the free RAM too? (the sdError() & freeRAM() functions for example?)
2.) editing some of the libraries directly? Maybe if Im not using some of the public functions.. remove them? Is this 'only' good for sketch size again? or helps with RAM?
3.) Maybe changing the data types or way I defined variables?
I still need to add more code/functionality to this sketch...but am hitting a wall without some advanced/divine intervention.. LOL
I still need to do the following:
1.) change the ammo counter/display workings (needs to start @ 300 max ammo.. go to 240 (-60)..then reload.. then down to 180 (-60), reload...then down to 120 (-60)...etc.. down to zero!.. where you reload again (and go back to full max ammo count of 300)..
Im assuming thats going to cost me some space/lines of code to implements..
*it already work from counting down from 300-0, so there is SOME code for it, but it'll need to be changed up.
(*dont ask why it has to be like that.. it makes NO sense.. but Im trying o replicate 'game play' from some video game on this project/prop, and thats how it behaves)
**2.)**In addition to the 3-digit, 7-segement display I'm updating now, I'll have another daisey chained MAX chip.. that consists of 30 x SMD leds.. in a bargraph configuration.. (which again will require more code, and space which I'm obviously running out of?) that will dim 1 x led for every 2 shots.. (ie: depleting the bargraph when the counter goes down 60 shots 'per' reload)
So I need to re-group and ask/learn about how I can optimize/streamline my code to make it smaller/compact..
Being a beginner, and not formally trained/taken classes.. I'm not sure if there is a place to start?
sketch attached:
thanks!
DC_17_OSv4_forum_3.ino (15.7 KB)