Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
I will post this and hope some will be interested.
http://youtu.be/pjDlpbPddCA
I am a complete novice with the code and admit I had lots of help. What I found was there is nothing to find for simple projects. So if there is any interest I could separate the two functions show here and do up the code for the library.
Cheers,
Ron
ronee Newbie
Joined: 08/01/2012 Location: CanadaPosts: 20
Posted: 03:04am 05 Mar 2012
Copy link to clipboard
Print this post
I had difficulty finding code examples to get started. Hopefully you will post your simple little snippets and we can have a library of "getting started" code examples for the complete novice, like myself...
Here then is a simple counter for rotating shafts and things that will provide a total count. This is not the code in the video, but similar.
10 ' Count Demo, Mick Gulovsen, Ron Pugh
20 '
30 Setpin 11,5
40 A=pin(11)
50 Print A
60 B=pin(11)
70 IF B>A then A=B: goto 50
80 goto 60
And the schematic
RonEdited by ronee 2012-03-06
ronee Newbie
Joined: 08/01/2012 Location: CanadaPosts: 20
Posted: 03:26am 05 Mar 2012
Copy link to clipboard
Print this post
Continuing on...
Here is a PWM example. This includes 'how to make a box'also
10 ' PWM1.bas using Sound output pin
11 ' Keith Williams, Ron Pugh
15 CLS
20 LINE(100, 100) - (300, 150), 1, B ' draws a box
30 Duty = 30 ' init to 30/70 PWM
40 Sound 200, 2000000, Duty ' 200 Hz duration about 33 minutes 50 % duty
50 LOCATE 115, 120 ' where to print in box
55 FONT #2 ' big print
60 I$=Inkey$ : if I$="" then goto 60 ' Test for keyboard input until key press
70 If I$="z" Then Duty = 15 : Print"Speed 15 %" : GoTo 120
80 If I$="x" Then Duty = 25 : Print"Speed 25 %" : GoTo 120
90 If I$="c" Then Duty = 40 : Print"Speed 40 %" : GoTo 120
91 If I$="v" Then Duty = 50 : Print"Speed 50 %" : GoTo 120
92 If I$="b" Then Duty = 60 : Print"Speed 60 %" : GoTo 120
93 If I$="n" Then Duty = 75 : Print"Speed 75 %" : GoTo 120
95 If I$="m" Then Duty = 100 : Print "Speed 100 %" : GoTo 120
100 GoTo 60
110 '
120 Sound 200, 2000000, Duty
130 GoTo 50
This is not the code used in the video but similar...
Here is the schematic
And a picture of the CGMMStick on its board
Ron
crackerjack
Senior Member
Joined: 11/07/2011 Location: AustraliaPosts: 164
Posted: 12:40pm 05 Mar 2012
Copy link to clipboard
Print this post
Hi Ron,
Looks like you are having fun with the Maximite. I think there is a growing "library" of code and circuits for the Maximite which will just increase as the *Mite family becomes more well known and people see how easy and fun it is to experiment with.
As far as your code posted above; I just have two questions/observations hopefully they will help with your (and other's) learning. They are definitely not criticism's.
1) I am not sure of the purpose of lines 60 and 70 in the first listing. There doesn't seem to be a purpose to accumulating a value in B and Line 80 will never be reached (the GoTo 50 at the end of Line 70 ensures that). Maybe this is just a snippet of code and I can't see the "big picture"
2) In the second listing, Line 55 could be moved outside the loop. It is not necessary to keep setting the Font to #2. This simply uses up processing cycles to no avail. Once set, the font remains set until another, different font is set.
3) Also in the second listing, setting the duration of the SOUND command to such a long time period serves no purpose within the loop since the SOUND command is called again very soon. You could very likely reduce this to a very small number (say 5 milliseconds) and it would still do the job. Experiment anyway and post your findings...
Last word... Try using some of the new "lineless" features of MMBasic (since version 3.x) and Do..Loops instead of Goto's
Cheers.
ronee Newbie
Joined: 08/01/2012 Location: CanadaPosts: 20
Posted: 07:21pm 05 Mar 2012
Copy link to clipboard
Print this post
Thanks for the feed back cracker jack!
Yes I posted this to get corrections so no problem.
Line 60 and 70 was to get it to print the following number. At first it prints only a series of 1's with out pause.
Your other points well taken, especially the long duration call
I find at this point line numbers help me find my way around the code. If and when Hugh puts this up in the library he has rewritten this without line numbers and using Do loops and Elseif's which I have asked him to post along side the above (and with his name on it)