Ann: Program to run loom- maybe of interest as a case study?

I've recently written a program to run loom. It could be adapted for other things, say to ring "tunes" on wind chimes. But the main reason for mentioning it here is that it might be useful "vegetables" for novice programmers. Go through the code, whether you are building a loom or not. Look at what was done. Try to figure out why it was done as it was.

It's ironic, really. Any computer studies course claims that a loom was the first programmable device. (It was "programmed" with punched cards. Change the cards, and you would weave a different fabric. Now, 2015, we come full circle: A program to control a loom. This was the fruits of an actual "job" to create a real program for a real loom. The write up has rough edges, but it takes you through what the program does, and how it might be adapted for different requirements. The program is in good shape, and illustrates some Best Practice ways of doing things. What this does not have is a lot of tutorial material.

Full code, and some discussion, at...

"Reviews" as to whether the material is any good, of any use, of use to whom, welcome here as "replies"... but please be gentle!

tkbyd:
This was the fruits of an actual "job" to create a real program for a real loom.

So it's a "Fruit of the Loom"? :slight_smile:

but this will never work:

byte bDelayBetween=1200;

Can you see why?

Also, I commend you on using so many comments. But I think the claim about illustrating Best Practices is, well, a little bit specious for what you have there. Not to say it isn't good.

Oops! Quite right... thank you....

bDelayBetween=255 would be okay. (Or is the limit 127?)... but for longer delays, the varible name should be changed, although the sloppy, and will-end-in-tears kludge of....

int bDelayBetween=1200

...would "work"..... until you tripped over something, confused by the badly chosen name.

Thanks again. Apologies to any novices who get caught by that.

(The listing on the webpage has been changed. The error persists in the .zip file, and it is a nasty error because the compiler won't catch it, but the delay will be less than you will be expecting.)

"Fruit of the loom"? Very good! (^_^)

We would usually use a 2-dimensional array for this kind of thing:

char *pattern[] = [
"0111110000000000000000000000000000000000",
"1011101000000000000000000000000000000000",
"1101011000000000000000000000000000000000",
"1110111000000000000000000000000000000000",
"0000000000000000000000000000000000000000",
""
];

I don't know if C++ will permit a pattern[][41] to be initialised in this way.

This means that you do not need to copy things around.

Almost. {} vs [] tho.

char *pattern[] = {
"0111110000000000000000000000000000000000",
"1011101000000000000000000000000000000000",
"1101011000000000000000000000000000000000",
"1110111000000000000000000000000000000000",
"0000000000000000000000000000000000000000",
""
};

I think I would do it as hex characters tho:

byte *pattern[] = {
0x7c,0,0,0,0,
0xba,0,0,0,0,
0xb6,0,0,0,0,
0xee,0,0,0,0,
};

CrossRoads:
I think I would do it as hex characters tho:

Much easier to see the pattern with binary data.

Better still, write a PC program to make the pattern data from an image.

I don't have time to study this now, but I have bookmarked it for the future as I have been thinking of building a small loom to produce small images - a bit like cross-stitch.

...R

Helpful comments! Thank you! I funked arrays because I find that they are particularly hard for novices to cope with. It made me squirm, though, as so many things could be so much more elegant and flexible in this program.

Thank you, Cross, for the

Almost. {} vs [] tho.

I think that would "fix" my need to keep copying things into the buffer variable, something else that I didn't like about my program. (Even if I still didn't use arrays, but maybe not. I'm sure I'll see when it comes time to write Version 2!

I have it installed on my loom and it's working nicely. It could also be used for running a steam calliope with a little modification.