Is there a way to download to the PC the program that is currently running on the Arduino?
As in: if you are playing around with different versions of a sketch, take a break, and can't remember which sketch is currently loaded, is there a way to find out other than running it and seeing what happens and comparing?
I think theoretically AVRDUDE could be used to download the contents of the flash memory to the PC as a .hex file. hen that file would need to be compared to the .hex files from various suspect sketches. Tedious at best, including finding where the Arduino IDE hides the .hex files. I'd probably go with Post-It (c) notes or something
Is there a way to download to the PC the program that is currently running on the Arduino?
You could get the HEX data from the chip, but you would not be able to convert that back to the original C.
ncluding finding where the Arduino IDE hides the .hex files.
The real issue is that the IDE deletes the HEX after upload. If you hold-shift while clicking verify / upload, the IDE will save the HEX and tell you where it is located.
Or would it be optimized away by the compiler if not used?
I don't think it would get optimized out. If you calculate at run-time the memory location to be used, how would the complier know which parts of PROGMEM are unnecessary?
The addition of the Serial.print() seems like a good practice, in sketches that can or already use Serial().