PDA

View Full Version : Creative ways to make macros with the least amount of code space



plyrathrt
- 15th September 2014, 23:32
So I have been thinking about making a project to create macros but can't think of a creative way to save on the code space.

Here is a simple way of explaining what I am attempting to do.

So lets say we have 5 leds and each has it's it's own tactile switch to turn it on. The way I have envisioned the code is have an included file called "button checks" which has a routine that checks each button (tris register) and sets a bit if the button is pressed. In the main program, you have the routines that check the bits and turn on the LED if the bit returns the expected value.

Now, say I want to have a "macro" button that can be programmed to turn on a particular set of LED's when it's pressed. So of course you would have a programming mode and while it's in the programming mode, you would press the buttons for which leds you want to turn on with the macro button. So out of the 5 led's, lets say I wanted the button to turn on the red and green leds with the macro button.

While I know I could do this using a lot of code space, I am trying to find a creative way to do it with the least amount of code space. There are a lot of commands in picbasic that I have yet to use, or use in the best way, that I am hoping will help keep this project low in code space.

Any thoughts?

Archangel
- 16th September 2014, 02:01
Using the TRIS register, simply state TRISx = %11111100 assuming you have already set the portx to %00000011 that would make outputs on. You would be switching between input and hot(logic 1) output. Why a macro?

plyrathrt
- 16th September 2014, 02:23
Maybe I didn't explain it right.

Lets say you had a keypad with button 0 to 10. Each button press is read as a number under normal operation. Now put a big read button on the wall and allow that button to be custom programmed to be any button combination. So I could make that big red button on the wall bee 554422 or 541874, whatever I wanted. So you would put that button in to a "programming mode" and then on the keypad, type in the sequence you want, exit programming mode and now the big red button does that sequence every time you press it. It's like using a gaming keypad on a computer. You can record a macro or keystrokes that are replayed when pressing the button you chose to use to play the macro back (in our case the big red button).

The only way I see to do this with little code space is getting creative with arrays but I have nearly zero experience with arrays.

Archangel
- 16th September 2014, 05:12
I'm a little weak with arrays too, but a keypad reader will require one. What you can do is have a subroutine with the master code and use the "big red button" control it. Mister_e did a keypad routine as an include, but you'll have to roll your own array to store the results.

EarlyBird2
- 18th September 2014, 08:59
Maybe I didn't explain it right.

Lets say you had a keypad with button 0 to 10. Each button press is read as a number under normal operation. Now put a big read button on the wall and allow that button to be custom programmed to be any button combination. So I could make that big red button on the wall bee 554422 or 541874, whatever I wanted. So you would put that button in to a "programming mode" and then on the keypad, type in the sequence you want, exit programming mode and now the big red button does that sequence every time you press it. It's like using a gaming keypad on a computer. You can record a macro or keystrokes that are replayed when pressing the button you chose to use to play the macro back (in our case the big red button).Sound easy enough to me.


The only way I see to do this with little code space is getting creative with arrays but I have nearly zero experience with arrays.Looks like a good reason to learn. Let me know if you want me to help.