Please post your complete code within </> code tags, within this code you appear to be using maybe 40 bytes of ram. Unless you mean flash memory, but then what board are you using /
david_2018:
No memory problems with the code you posted. Are you confusing program storage space with dynamic memory?
Arduino: 1.6.12 (Windows 10), Board: "ATtiny25/45/85, ATtiny25, Internal 1 MHz"
Sketch uses 2,402 bytes (117%) of program storage space. Maximum is 2,048 bytes.
Global variables use 30 bytes (23%) of dynamic memory, leaving 98 bytes for local variables. Maximum is 128 bytes.
processing.app.debug.RunnerException: Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.
at cc.arduino.Compiler.size(Compiler.java:335)
at cc.arduino.Compiler.build(Compiler.java:159)
at processing.app.SketchController.build(SketchController.java:641)
at processing.app.Editor$BuildHandler.run(Editor.java:1782)
at java.lang.Thread.run(Thread.java:745)
Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Aha, an ATtiny... explains the memory problem. If you replace all the floating point calculations with integer calculations, you should be okay. The floating point routines use a lot of program memory.
Even on an ATtiny you should be able to fit this into a 25, i think i can fit it into a 13a. If you use an active piezo instead of a passive one, you don't need tone anymore. using floating point calculation here(timeTaken/2)/29.1 sucks up the rest. You will just have to remove the fraction and modify the comparison to that result. And you should do the multiplication before the division (keeping an eye on the size of the variable) for the sake of accuracy.
Actually, there is no need to calculate 'distance' at all. Instead, craft constant expressions for distances and compare those directly with 'timeTaken'.
No, but we were going to find that out once the skecth fits into memory. The pins are referenced by their PB (0-5) but as far as i know there are some complications for PB5, being also the reset pin. If you want to use it as a normal pin there is something you can do, or it is useable as an input pin wit limited range.