Shop OBEX P1 Docs P2 Docs Learn Events
Need suggestions on shortening code; EEPROM is full! — Parallax Forums

Need suggestions on shortening code; EEPROM is full!

ElectricbeesElectricbees Posts: 1
edited 2012-12-04 20:44 in Learn with BlocklyProp
Working on a multi-task robot for a freshman class.

BOEbot is supposed to flash a sequence of 10 LED's (When lights are on, and the push button is not pressed)
It should also play a song and flash a different set of LEDs for when the button is pressed, and the lights are on.
Third, it plays a second song and a third sequence of lights for when the lights are off, regardless of button presses.

My coding is pretty brute-force in style, and I'm wondering if there is a way for me to cut down a lot of my lines?
Do lines/characters/commands fill up the EEPROM? I mean, does it store the same amount of data per line, command or character?

For playing a note with an LED, my code looks like this:

HIGH 7
HIGH 10
FREQOUT...............
LOW 7
LOW 10

Can I by chance, shorten those commands? Or make them store less memory on the EEPROM?

Attached is my .bs2 file.

Thanks for any suggestions!BOEBOTproject.bs2

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-12-04 20:40
    You can't shorten the commands. They're already short. A HIGH and LOW and FREQOUT really don't take a lot of memory. It's just that you have so many of them. What you do is look for the commonality where things are repeated over and over again and you substitute a CALL to a subroutine for the group of statements. For music, you might use an interpreter where each note is represented as a single byte in a DATA table. You fetch these one at a time using a READ statement, then flash the appropriate LEDs and make the appropriate note, then go on to the next note.

    You can set up the LED sequences the same way with a table giving the sequence (assuming that the sequence advances with each note). Your music interpreter can also sequence through one of the LED tables as it advances from one note to another.

    You'll need to describe in more detail what the songs are, what the LED sequences are, how these interact with the pushbuttons, etc.
  • davejamesdavejames Posts: 4,047
    edited 2012-12-04 20:44
    Hi EB - welcome to the Forum!

    The only thing that jumped out when I perused the code is that the initial 14 lines of OUTPUT and the 2 lines of INPUT could be handled by the DIRS command (check the manual). It will allow you to set the I/O state of pins with one command.

    Toward the bottom of Loop1, there is another group of pins being set to all HIGH and a group to all LOW. This again could be handled the same.

    Otherwise, the resident Forum Wizards may have something to say.



    ...I see Mr. Green has chimed in with very relevant insight.
Sign In or Register to comment.