# Extra PICAXE Wizards

#### nick12ab

##### Senior Member
Nick, here is a "checkBattery" routine that I am using. It isn't exactly linear, but I ran out of time researching the "correct" way to do this and just adjusted the numbers until I got it right at 12VDC and close enough at 15VDC and 11VDC.
So when you say that it is 'close enough' at 15V and 11V, do you mean that they are both the same side of 12V with the skew or is one more and the other less as if the value reported by the PICAXE had some sort of logarithmic relationship with the actual input? My guess is the former, in which case it would be a problem with the multiply and divide combination.

Code:
``````checkBattery:		'Compares battery voltage at divider to fixed minimum; sets flag

batteryLow = 0

' "40" = 4 for the voltage divider and 10 to scale the factor to an integer
' "273" = 1024 divided by 3.75 (15v / 4) rounded to scale it to an integer

if batteryVoltage < BATVOLTMIN AND batteryVoltage > 5000 then	' 5000 = 5 volts
batteryLow = batteryVoltage	' this can be used as a previous voltage value
else
batteryLow = 0
endif
return``````
16 is calculated by my program. The result will be 100 times bigger (as your multiply and divide combination was approximately 0.16). See how you get on with it.

#### techElder

##### Well-known member
Not ignoring you, Nick. My hardware is out on trial, and I'm working on new hardware. So, I can't verify your "16" multiplier. However, I think I did try it before without good results.

Yes, there is a problem with my multiply and divide combination. The numbers returned are high on one side of 12V and low on the other.

#### techElder

##### Well-known member
Table Wizard

Here's another wizard for you, and perhaps more challenging with graphics!

The result is a table of byte values that represents a linear sequence of bytes to be applied to an output port. Something like this:

Code:
``````table 0x00,(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00)
table 0x10,(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00)
table 0x20,(0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00)``````
Now, the challenge is to provide the interface that looks like this:

7-XX XX
6- XX XX
5- XX XX
4-X XX XX
3- XX XX
2- XX XX
1- XX XX
0-X X X

The byte values in the table represent the column values in the graph. This makes it much easier to visualize the bit settings.

Your graphic would keep the programmer from having to build the table in binary representation just to see which bits are set; like this:

Code:
``table 0x00,(10010001,11101110,01111111,00000000,00000000,00000000,00000000,...)``
The number of columns could vary and be specified. Copy and paste of blocks would be tremendously valuable.

#### nick12ab

##### Senior Member
Just to make sure I understand before I put in effort -
you want there to be a table of eight rows and adjustable amount columns where the user sets the bits and then it generates a table command in hex?

#### techElder

##### Well-known member
Yes, but loading up EEPROM statements could benefit, too. This could be handy with LCD custom characters.

Also, I can see where a programmer may just want to program just the upper or lower nibble and zero out the other nibble.

I can also see where a programmer might want to set the bits for more than 8-bits. Perhaps adjust into 10 or 12 or 16 bits? Could be handy for large LED arrays?

Just to make sure I understand before I put in effort -
you want there to be a table of eight rows and adjustable amount columns where the user sets the bits and then it generates a table command in hex?

#### nick12ab

##### Senior Member
Ok, I'll work on this when I have a decent amount of spare time.
• 8 - 16 bits
• Choice between EEPROM and Table (and LOOKUP)

#### nick12ab

##### Senior Member
Looking for some help

In order to do Texasclodhopper's request, I will need to use an array - likely to be of checkboxes. However it will need to be on a panel on one of the tabs and the walkthrough by Microsoft only shows how to create the array on a form and does not help with panels. I found this but it didn't help either.

N.B. No help will probably result in Texasclodhopper's idea never being implemented.

The attachment is just the Microsoft walkthrough but with checkboxes rather than buttons. The main problem is that forms and classes in Visual Basic have to refer to themselves as Me if the code is executed by that form/class, but Me refers to whatever file you're writing the code in in Visual Studio so if when modifying the array class you try to set the parent of the checkboxes to 'Me.Panel1', it won't let you compile it and if you use 'Form1.Panel1', it will compile it but you will get a run time error.

#### Attachments

• 71.9 KB Views: 7

#### techElder

##### Well-known member
Hopefully, others need a visual method of creating table statements in PICAXE basic.

#### mrburnette

##### Senior Member
<...>The main problem is that forms and classes in Visual Basic have to refer to themselves as Me if the code is executed by that form/class, but Me refers to whatever file you're writing the code in in Visual Studio so if when modifying the array class you try to set the parent of the checkboxes to 'Me.Panel1', it won't let you compile it and if you use 'Form1.Panel1', it will compile it but you will get a run time error.

... 'tis been far too long and in another life, but do you not have to subclass the public array object into the private subroutine on Form1? Which is to say you will need a me.private_array which inherits from the public CheckBoxArray. Now, essentially your form and array are in the same instance.

- Ray

#### techElder

##### Well-known member
See, Nick? There are others interested in your wizard project!

#### nick12ab

##### Senior Member
... 'tis been far too long and in another life, but do you not have to subclass the public array object into the private subroutine on Form1? Which is to say you will need a me.private_array which inherits from the public CheckBoxArray. Now, essentially your form and array are in the same instance.

- Ray
Could you explain better please? I've never used arrays in Visual Basic before!

#### mrburnette

##### Senior Member
Oh, more than interested... a faithful follower of Nick's progress.

- Ray

#### techElder

##### Well-known member
Nick, the multiplier "16" calculated in the wizard does NOT work to give accurate battery numbers. Tested it at 14.8 VDC and got something around "180" to "190".

Also, on the TABLE wizard, I'm attaching a worksheet that I normally use. The worksheet is adequate for small table entries, but larger tables get cumbersome.

BTW, remember TABLE data extracted as WORDs is in Little Endian format.

View attachment 11300

Last edited:

#### nick12ab

##### Senior Member
Nick, the multiplier "16" calculated in the wizard does NOT work to give accurate battery numbers. Tested it at 14.8 VDC and got something around "180" to "190".
Are you using it correctly? The multiplier calculated in the wizard is multiplied by the ADC value to get Vin.

P.S. Still looking for help with the arrays.

#### techElder

##### Well-known member
Nick, my fault. When I used the multiply & divide method, I was able to keep the result within a byte width. With your multiply by 16 method, the number moves up into a word width. I get numbers similar to the following on a small bench-top power supply:

Code:
``````adcBatteryreading: 906  adcBatteryreading * 16: 14496
The move to a word variable is a distinct disadvantage.

#### nick12ab

##### Senior Member
I've got a new idea for the arrays - instead of trying to use a control array, my new idea will be a "custom control" array that is drawn using the Panel.Paint() event handler of the panel. The panel will have AutoScroll set to True.

Idea:
• Can be done: A variable says how many columns there are and there are buttons to change that
• Can be done: The Panel.Paint() event has code which draws lots of boxes in a FOR : NEXT loop
• Can be done: The width of the scrollable area in the panel is set, using a label with text set to nothing at the right hand side if necessary
• Can be done: The Panel.Click() event will use the e command to get the co-ordinates of the mouse inside the panel
• Can be done: IF statements in a loop to determine which square was clicked
• Can be done: A loop to generate the TABALE command
• Needs to be investigated: Binary or Boolean variable array to hold the bit pattern
Needs to be investigated = Haven't tested to see if Visual Basic supports this functionality.
The second and fourth points are probably how the controls provided in the Windows Forms Designer work but this code isn't exposed.

Edited: I've confirmed that you can get the coordinates of the mouse click, however I need to use a panel within a panel as just a panel on its own will return the coordinates relative to the visible edges of the panel, not the actual bounds of the panel. However this isn't a problem.

Last edited:

#### nick12ab

##### Senior Member
This is a demo of the "custom control array". It currently only has visual effect and doesn't yet do anything. If there are any problems with it so far, state them.

#### Attachments

• 73.5 KB Views: 15

#### nick12ab

##### Senior Member
I found that the best optimization with the graphics handling was to draw horizontal lines and then vertical lines instead of drawing little boxes and this is much faster. It will probably slow down again once colour fills have been added, but the small size of the wizard will mean that there isn't much that needs to be drawn at once.

I better get working on the variables array now.

#### techElder

##### Well-known member
You can do it ... just put your mind to it. We've seen your work so far and have confidence in you!

#### nick12ab

##### Senior Member
Progress update!

I've sucessfully been able to do the bit arrays now and attached is a little demo of it. You can't yet set the bits yourself but I've preloaded the array with a little bit of data.

Can you also comment on my choice of using dark green 'off' LEDs and light green 'on' LEDs - do you think it should be a different colour, or red and green instead of on and off?

Yes I know it's been over 2 weeks since the last version but this is my greatest programming challenge yet. Whilst I'm posting, I might as well just rant about having to use pen.colour for drawing shapes with lines, brush.colour for drawing filled shapes and color.colour for other uses of colours - why not just use color for everything? You get conversion errors if you try to use a different one.

#### Attachments

• 84.1 KB Views: 7

#### techElder

##### Well-known member
Not having VB programming set up on my system, I can't comment other than to question whether the LED is appropriate for everyone that would use the wizard. It certainly is for me, though.

#### techElder

##### Well-known member
Nick, just to throw the inevitable and proverbial monkey wrench into your ongoing project, the end user just might want to use some of the "high bits" of the table data as flags for various programming purposes; e.g. intensity control in an LED application. I'm not sure that would change anything that you are doing. Just FYI.

#### mrburnette

##### Senior Member
Whilst I'm posting, I might as well just rant about having to use pen.colour for drawing shapes with lines, brush.colour for drawing filled shapes and color.colour for other uses of colours - why not just use color for everything? You get conversion errors if you try to use a different one.
Generally, when you see multiple classes for features that you think could be just be one big object, the programmer had made multiple ones so that the compiler has the ability to make the code more granular; that is, someone thought that pen / brush / color may be used independently. Had all of the functions been put into color.x then a significant amount of code would need to be memory resident before any of the object functions could be utilized. Such things as code bloat and the need to pull large chunks of code from virtual memory (assuming the code chunk has been swapped out of main memory) are little things that can vastly affect library routines that have visual implications.

- Ray

#### nick12ab

##### Senior Member
Nick, just to throw the inevitable and proverbial monkey wrench into your ongoing project, the end user just might want to use some of the "high bits" of the table data as flags for various programming purposes; e.g. intensity control in an LED application. I'm not sure that would change anything that you are doing. Just FYI.
Er....? I don't understand.

My talk about the LEDs was about the appearance of the table below where you can see that the 'off' squares are dark green and the 'on' squares are lime.

Anyway, I've updated the prototype by doing away with drawing black gridlines for the squares and just using a black background but the biggest progression is that now I've got it so that clicking the squares now changes their bits. All that's left to do is to be able to convert this into a TABLE, LOOKUP or EEPROM command.

If possible, I'll then focus on being able to drag the mouse and toggle all bits it passes over.

#### nick12ab

##### Senior Member
I've got the table command generator to work (in decimal). The demo is attached and compiled - check the bin\relese folder. It's not perfect yet as you can't set the start address (that will be easy) and it does not exclude hidden bits (so if a bit pattern used bits beyond the first 8 then it was set to only 8 bits the other bits would still be included in the table command).

On the dragging, I've tried moving the code to the Panel.Move() event handler instead of the Panel.MouseDown() event handler and I've added extra variables and if statements to determine whether the mouse has moved to another square or not and it worked with the exception that you had to move the mouse by a pixel to get the first square to change so I've reverted it. It isn't really a necessary feature but it would be a good one to add!

On a plus note, I've finally confirmed what += is, and it does append the result of the following calculation to the existing one, so var += 1 is like inc var on PICAXE.

#### Attachments

• 84.7 KB Views: 7

#### techElder

##### Well-known member
Your terminology is "hidden bits", and these are what I'm speaking of. A programmer may want those bits included with the non-hidden bits so he/she could visibly set them, too. Anyway, that would be taken care of by expanding the graph to include those bits.

So, by jove I think he's got it! Looks like a wiener to me, and I can hardly wait to use it on my current project.

Er....? I don't understand. ... and it does not exclude hidden bits (so if a bit pattern used bits beyond the first 8 then it was set to only 8 bits the other bits would still be included in the table command).

#### techElder

##### Well-known member
I tried the "tempProject18.exe. Works as expected.

I am a little concerned with the square sizes getting smaller as the number of bits gets higher, but I see the problem with screen space.

Don't forget "Little Endian" when you get to the "0x00" format. EDIT: See EDIT NOTE below.

Eventually, someone will ask to be able to drag across the pixels to set or reset whole blocks of bits. (No, not me! ) Perhaps with the SHIFT and CTRL keys? Don't forget about SET ALL and RESET ALL.

EDIT NOTE: I was referring to the capability to read TABLE data as WORDs when the BITS (vertical in your graph) extend beyond 16.

Last edited:

#### nick12ab

##### Senior Member
Version 1.10

• Generates commands with hexadecimal numbers according to interactive bitmap
• Clicking + dragging will either toggle all other cells/bits the mouse passes over or change them to the same state as the first bit
• Clears extra bits when reducing number of bits
• Automatically disables bits selection and sets it to 8 bits when using a command other than lookup
• Designed to look like a green LED matrix
Changes:
• Command to use textboxes for all commands with room for it are expanded to fill the remaining space
No I have not done 'Set all' and 'Clear all' buttons yet but those will be quite simple and I'll add them for the next release.

#### Attachments

• 83.7 KB Views: 9
• 395.7 KB Views: 3

#### techElder

##### Well-known member
Works like a charm! Exactly matches the data that I created manually.

Now for the nitpickin' ...

I prefer the hex format "0x00" because I can see the individual nibbles. Perhaps a check box for format of the data and addresses?

There's a bit of display flashing while dragging.

I will always keep the "copies first bit" box checked. Makes more sense to me.

Good show!

#### techElder

##### Well-known member
I noticed that it is possible to use a start address of "511" with 16 columns. So, just correct the start address to account for the number of columns if it's near the end of table space.

#### nick12ab

##### Senior Member
I prefer the hex format "0x00" because I can see the individual nibbles. Perhaps a check box for format of the data and addresses?

There's a bit of display flashing while dragging.
This is due to the time taken to draw the cells. I'm not sure how to get around this so can you help?

I will always keep the "copies first bit" box checked. Makes more sense to me.
Another easy change.

I noticed that it is possible to use a start address of "511" with 16 columns. So, just correct the start address to account for the number of columns if it's near the end of table space.
This should be an easy addition using:
Code:
``NumericUpDown.Value = 512 - [I]cols[/I]``

#### techElder

##### Well-known member
"0x00" is a format for HEX just as "\$00" is a format for HEX. "0x00" is a fixed width format that shows both nibbles. I prefer to see it that way. That's all I'm going to say.

#### nick12ab

##### Senior Member
"0x00" is a format for HEX just as "\$00" is a format for HEX. "0x00" is a fixed width format that shows both nibbles. I prefer to see it that way. That's all I'm going to say.
Both show both nibbles, however Rev-Ed seem to steer towards \$ rather than 0x (which could falsely be read as "zero-times") and it takes up less space. I've done some testing and with the table set to 512 columns and the MSb of each 16-bit word set high the entire command is too long and only about 2000 characters are scrollable within Programming Editor before you can't see anymore - let's not make that worst.

By the way, VB removes leading zeroes from hex numbers that are converted to strings.

#### nick12ab

##### Senior Member
Version 1.10.1

• More tooltips added to the bitmap wizard
• Set all bits
• Clear all bits
• Invert all bits
• AND, OR and XOR all words with another
Changes:
• Dragging copies first bit instead of toggling now enabled by default
• Columns count now shown in Columns: label before -/+ buttons rather than in a dedicated label after the buttons
• Corrected TabIndex properties of options for bitmap wizard

#### Attachments

• 423.2 KB Views: 7
• 90.9 KB Views: 10

#### techElder

##### Well-known member
Everything that I tried works for me. Fine program and makes my job much easier. I can make patterns with this that I wouldn't have tried by hand.

Nit-pickin' again ... I'm thinking that the "Cols (x)" control should be like the "Start address" control. Much easier to use.

#### nick12ab

##### Senior Member
Version 1.10.2

• Automatically calculates maximum number of columns based on start address (lookup/eeprom only) and command
Changes:
• Columns counter now uses NumericUpDown control
Not going to bother upload source code now, will do for the next release.

#### Attachments

• 90.9 KB Views: 26

#### techElder

Works for me!

##### New Member
Just what I was looking for - Thanks

#### nick12ab

##### Senior Member
Version 1.10.3

It turns out I forgot to upload this version with the last post. I've now done the resistor value display properly and I'll delete that last useless post. Let's just forget that "previous version 1.10.3" - this is the proper one.

• Label below resistor in resistor colour code calculator that says what the resistance is in order to prevent the outlines of the comboboxes from confusing users in to thinking that there's a decimal point where there isn't.

#### Attachments

• 91.2 KB Views: 34

#### mrburnette

##### Senior Member
@nick

Very fine piece of VB... congrats. You do realize that if you are not presently wearing eyeglasses that you will be soon?

- Ray