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.
|
Forum Index : Microcontroller and PC projects : gauge bezel problem
Author | Message | ||||
oldtimer Newbie Joined: 02/12/2016 Location: AustraliaPosts: 18 |
Hi all Im trying to duplicate the single and 6 gauge cluster bezel as written by Matherp without much sucess - trying to achieve a circle with white ,green ,yellow and red segments as shown in many photos Having achieved that - I may then be able to then insert a needle command to allow the gauge to show a value from an attached sensor- 1 step at a time however Ive run the code many times - even tried running parts of it relating to the bezel commands -but always get an "unknown command" error when the program hits the "segment " line If "segment" is an unknown command - how does one achieve the gauge bezels shown complete with division marks - I note that the addition of "15" in the correct position does this in the program for the 6 gauge cluster which Ive managed to download and run without problems I have wondered if the attached C function codes contain some way of dividing the segments up into specified divisions - if that is the case - it seems to me to defeat the object somewhat of "BASIC" which allows one to experiment with changing values within the code to see what happens- I do realise that c functions provide "better and faster" but to the uninitiated -when confronted with a large list of apparently meaningless numbers one then has to rely entirely on the person who wrote the code -I should mention -I have little ability with coding and NONE with c functions- Can anyone tell me why " segment" - isnt recognized as a valid MM basic command - in spite of being included in almost all the gauge codes for the 28 pin micromites I would appreciate any comments |
||||
disco4now Guru Joined: 18/12/2014 Location: AustraliaPosts: 844 |
segment is not an MMBASIC command. The subroutine below is probably what is be referred to. This was taken from the threads you have been referring to. Do you have this anywhere in your code. ' ' ' Routine to draw a segment of a circle ' Parameters are: ' x-coordinate of centre of circle ' y-coordinate of centre of circle ' radius of circle ' start radial of segment to be drawn (0-360 degrees) ' end radial of segment to be drawn (0-360 degrees) ' colour to draw segment ' inner radius for drawing radial lines, leave blank or set to zero if not required ' ' NB if start radial and end radial are the same a line will be drawn ' Sub segment(x As integer, y As integer, outsize As integer, startradial As integer, endradial As integer, col As integer, insize as integer ) Local integer i,j,x1,x2,y1,y2,sr,er,xx0(1),yy0(1),xx1(1),yy1(1),xx2(1),yy2(1),tcol(1) If startradial=endradial Then x2=Sin(Rad(startradial))*outsize + x y2=-Cos(Rad(startradial))*outsize + y x1=Sin(Rad(startradial))*insize + x 'insize is 0 if not specified so a complete line from the centre is drawn y1=-Cos(Rad(startradial))*insize + y Line x1,y1,x2,y2,,col Else If startradial<endradial Then sr=startradial er=endradial Else er=startradial sr=endradial EndIf For i=sr+stepsize To er Step stepsize x2=Sin(Rad(i))*outsize + x y2=-Cos(Rad(i))*outsize + y x1=Sin(Rad(i-stepsize))*outsize + x y1=-Cos(Rad(i-stepsize))*outsize + y xx0(0)=x yy0(0)=y xx1(0)=x1 yy1(0)=y1 xx2(0)=x2 yy2(0)=y2 tcol(0)=col j=triangles(1,xx0(),yy0(),xx1(),yy1(),xx2(),yy2(),tcol()) Next i EndIf End Sub Regards Gerry Latest F4 Latest H7 |
||||
oldtimer Newbie Joined: 02/12/2016 Location: AustraliaPosts: 18 |
Hi Gerry Thanks for your reply and code - Ive cut and pasted it into the original and now get the following response ( with ref to the J=triangles (1,xx0)etc on line 169 if you've using MM EDIT)- error: invalid dimensions - I've attached the code in its present form in the hope you might be able to see the fault which is preventing the gauge from displaying - Ive noticed the coding in the last few lines of your code is somewhat different to Matherps original with ref to the J=triangles - his being j=triangle(x1,y1,x2,y2,x,y,colour,colour) - don't know if this might be upsetting the running of the code as always - any comments are welcome regards Bill Option default none Option explicit CPU 48 Const stepsize=3 const displaystring="EGT" dim integer lastx1, lastx2, lastx3, lasty1, lasty2, lasty3 ' Global variables to store last pointer position Const greenstart=-150, yellowstart=0, redstart=75, blackstart = 150 ' position of display bands in degrees - must be in ascending order Dim integer i, radius, firsttime=1, needlelength If MM.HRes<=MM.VRes Then ' set the radius of the display less the "bezel" radius=MM.HRes/2-4 Else radius=MM.VRes/2-4 EndIf needlelength= radius\5*4-1 Circle MM.HRes\2,MM.VRes\2,radius+3,0,,RGB(210,210,210),RGB(210,210,210) 'background to creat the bezel segment(MM.HRes\2,MM.VRes\2,radius,greenstart,yellowstart, RGB(green)) segment(MM.HRes\2,MM.VRes\2,radius,yellowstart,redstart, RGB(yellow)) segment(MM.HRes\2,MM.VRes\2,radius,redstart,blackstart, RGB(red)) segment(MM.HRes\2,MM.VRes\2,radius,blackstart,greenstart+360, 0) Circle MM.HRes\2,MM.VRes\2,needlelength+1,0,,0,0 text mm.hres\2-len(displaystring)*4,mm.hres-20,displaystring ' string centred in black segment do ' run the pointer backwards and forwards For i=greenstart To blackstart-1 needle(MM.HRes/2,MM.VRes/2,needlelength,i,RGB(white)) pause 10 Next i For i=blackstart-1 To greenstart Step -1 needle(MM.HRes/2,MM.VRes/2,needlelength,i,RGB(white)) pause 10 Next i loop End ' ' ' Routine to draw a pointer ' Parameters are: ' x-coordinate of centre of gauge ' y-coordinate of centre of gauge ' pointer length ' radial of pointer to be drawn (0-360 degrees) ' colour to draw pointer ' Sub needle(x As integer, y As integer, size As integer, angle As integer, col As integer) Local integer x1,y1,x2,y2,x3,y3,x4,y4,j x1=Sin(Rad(angle-90))*size/10 + x y1=-Cos(Rad(angle-90))*size/10 + y x2=Sin(Rad(angle))*size + x y2=-Cos(Rad(angle))*size + y x3=Sin(Rad(angle+90))*size/10 + x y3=-Cos(Rad(angle+90))*size/10 + y if not firsttime then j=triangle(lastx1,lasty1,lastx2,lasty2,lastx3,lasty3,0,0) else firsttime=0 endif j=triangle(x1,y1,x2,y2,x3,y3,col,col) Circle x,y,size\10,0,,col,col) Circle x,y,size\15,0,,0,0 Circle x,y,size\20,0,,RGB(240,240,240),RGB(240,240,240) lastx1=x1 lastx2=x2 lastx3=x3 lasty1=y1 lasty2=y2 lasty3=y3 End Sub ' ' ' ' Routine to initialise a gauge ' Parameters are: ' gaugeindex ' x-coordinate of centre of gauge ' y-coordinate of centre of gauge ' radius of gauge ' font size ' start radial of white segment (-180 to 180) ' start radial of green segment (-180 to 180, must be greater or equal to start of previous segment) ' start radial of yellow segment (-180 to 180, must be greater or equal to start of previous segment) ' start radial of red segment (-180 to 180, must be greater or equal to start of previous segment) ' start radial of black segment (-180 to 180, must be greater or equal to start of previous segment) ' string to display as gauge title ' spacing in degrees for any scale markers, set to zero or omit if not required ' sub initgauge(gaugeindex% , xpos%, ypos%, gsize%, fontmult%, whitestart%, greenstart%, yellowstart%, redstart%, blackstart%, displaystring$, tickspace%) local ticks% Circle xpos%,ypos%,gsize%+3,0,,RGB(210,210,210),RGB(210,210,210) 'background to create the bezel segment(xpos%,ypos%,gsize%,whitestart%,greenstart%, RGB(white),0) segment(xpos%,ypos%,gsize%,greenstart%,yellowstart%, RGB(green),0) segment(xpos%,ypos%,gsize%,yellowstart%,redstart%, RGB(yellow),0) segment(xpos%,ypos%,gsize%,redstart%,blackstart%, RGB(red),0) segment(xpos%,ypos%,gsize%,blackstart%,whitestart%+360, 0) segment(xpos%,ypos%,gsize%,greenstart%,greenstart%, 0) segment(xpos%,ypos%,gsize%,yellowstart%,yellowstart%, 0) segment(xpos%,ypos%,gsize%,redstart%,redstart%, 0) if tickspace% then for ticks%=whitestart% to blackstart% step tickspace% segment(xpos%,ypos%,gsize%,ticks%,ticks%, 0, (gsize%*19)\20) next ticks% endif Circle xpos%,ypos%, (gsize%*4)\5,0,,0,0 text xpos%-len(displaystring$)*4*fontmult%,ypos%+gsize%-fontmult%*28,displaystring$ ' string centred in black segment x(gaugeindex%)=xpos% y(gaugeindex%)=ypos% radius(gaugeindex%)=gsize% fontsize(gaugeindex%)=fontmult% lastx1(gaugeindex%)=xpos% lastx2(gaugeindex%)=xpos%+2 lastx3(gaugeindex%)=xpos%+2 lasty1(gaugeindex%)=ypos% lasty2(gaugeindex%)=ypos%+2 lasty3(gaugeindex%)=ypos% whitesec(gaugeindex%)=whitestart% greensec(gaugeindex%)=greenstart% yellowsec(gaugeindex%)=yellowstart% redsec(gaugeindex%)=redstart% blacksec(gaugeindex%)=blackstart% end sub ' ' ' Routine to draw a segment of a circle ' Parameters are: ' x-coordinate of centre of circle ' y-coordinate of centre of circle ' radius of circle ' start radial of segment to be drawn (0-360 degrees) ' end radial of segment to be drawn (0-360 degrees) ' colour to draw segment ' inner radius for drawing radial lines, leave blank or set to zero if not required ' ' NB if start radial and end radial are the same a line will be drawn ' Sub segment(x As integer, y As integer, outsize As integer, startradial As integer, endradial As integer, col As integer, insize as integer ) Local integer i,j,x1,x2,y1,y2,sr,er,xx0(1),yy0(1),xx1(1),yy1(1),xx2(1),yy2(1),tcol(1) If startradial=endradial Then x2=Sin(Rad(startradial))*outsize + x y2=-Cos(Rad(startradial))*outsize + y x1=Sin(Rad(startradial))*insize + x 'insize is 0 if not specified so a complete line from the centre is drawn y1=-Cos(Rad(startradial))*insize + y Line x1,y1,x2,y2,,col Else If startradial<endradial Then sr=startradial er=endradial Else er=startradial sr=endradial EndIf For i=sr+stepsize To er Step stepsize x2=Sin(Rad(i))*outsize + x y2=-Cos(Rad(i))*outsize + y x1=Sin(Rad(i-stepsize))*outsize + x y1=-Cos(Rad(i-stepsize))*outsize + y xx0(0)=x yy0(0)=y xx1(0)=x1 yy1(0)=y1 xx2(0)=x2 yy2(0)=y2 tcol(0)=col j=triangles(1,xx0(),yy0(),xx1(),yy1(),xx2(),yy2(),tcol()) Next i EndIf End Sub ' ' ' Routine to draw a triangle ' ' Parameters are: ' x-coordinate of first point ' y-coordinate of first point ' x-coordinate of second point ' y-coordinate of second point ' x-coordinate of third point ' y-coordinate of third point ' colour to draw triangle outline ' colour to fill triangle use -1 for outline only ' CFunction triangle 00000000 27bdffa0 afb40048 8fb4007c 8ce90000 8e820000 afa50064 8fa30064 afa60068 afa7006c 8fa70070 afa40060 8c850000 8c660000 8fa40068 8fa30074 8ce80000 2407ffff afbe0058 afb70054 8c9e0000 8c770000 afbf005c afb60050 afb5004c afb30044 afb20040 afb1003c afb00038 00401821 104700f4 8e840004 0126202a afa60020 afa90018 10800005 00a09821 03c09821 afa90020 afa60018 00a0f021 8fa50018 02e5202a 10800006 afa80024 03c02021 afb70018 0100f021 00a0b821 afa40024 8fa60020 8fa70018 00e6202a 148000ac 02602021 8fa40020 509700b0 03d3182a 8fa70018 10f70002 8fa60018 24e6ffff 8fa90020 00c9202a 148000e1 8fa70024 8fa20018 03d32823 00f32023 0049b023 02e9a823 afbe0028 afb7002c afb4001c 01208021 00009021 00008821 3c029d00 00a0b821 0080f021 10000003 00c0a021 8fa4001c 8c830000 0236001a 02c001f4 02002821 02003821 02378821 26100001 00002012 0255001a 02a001f4 00932021 00804021 00003012 00d33021 00c4482a 11200003 025e9021 00c02021 01003021 afa30010 8c430048 0060f809 afa20030 0290182a 1060ffe6 8fa20030 8fb4001c 8fbe0028 8e830000 8fb7002c 00601021 02f0202a 148000ab 8fa70018 8fa50024 8fa90020 00b3b023 00be3023 02079023 02098823 02e92023 72368802 afb40018 afa6001c 02c0a021 72469002 0260b021 02e7a823 3c029d00 10000003 00809821 8fa40018 8c830000 0255001a 02a001f4 8fa6001c 02002821 02469021 02003821 26100001 00002012 0233001a 026001f4 009e2021 00804021 00003012 00d63021 00c4482a 11200003 02348821 00c02021 01003021 afa30010 8c430048 0060f809 afa20030 02f0182a 1060ffe5 8fa20030 8fb40018 8e830000 8e840004 8fa50078 8ca20000 1043005d 8ca50004 8fa3006c 8fa60060 8fa70064 8fa90068 24110001 8cc40000 8ce50000 8d260000 8c670000 3c109d00 afb10010 afa20014 8e020050 0040f809 00000000 8fa40078 8fa50068 8c820000 8fa6006c 8fa70070 8fa90074 8ca40000 8cc50000 8ce60000 8d270000 afb10010 afa20014 8e020050 0040f809 00000000 8fa30078 8fa50070 8c620000 8fa60074 8fa70060 8fa90064 8ca40000 8cc50000 8ce60000 8d270000 afb10010 afa20014 8e020050 0040f809 00000000 8fbf005c 8fbe0058 8fb70054 8fb60050 8fb5004c 8fb40048 8fb30044 8fb20040 8fb1003c 8fb00038 03e00008 27bd0060 afa70020 03c09821 0080f021 8fa40020 1497ff53 afa60018 03d3182a 1460002d 8fa50024 027e182a 14600030 03c03821 02603821 02602021 8fa50024 00a4182a 54600003 8fa40024 00e5182a 00a3380b 8fa60020 afa20010 3c029d00 00e63821 8c420048 00c02821 00e43823 0040f809 00803021 8fa50078 8e830000 8ca20000 8e840004 1443ffa5 8ca50004 54a4ffa4 8fa3006c 8fbf005c 8fbe0058 8fb70054 8fb60050 8fb5004c 8fb40048 8fb30044 8fb20040 8fb1003c 8fb00038 03e00008 27bd0060 5482ff0d 0126202a 1000ff90 8fa50078 03c02021 00a4182a 1060ffda 02603821 1000ffda 8fa40024 1000ffd2 02602021 00401821 1000ff84 8e840004 1000ff4f 8fb00020 End CFunction |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5917 |
I haven't tried to run your program or any of the triangle code so I am not able to give a quick answer but I have noticed a possible problem You code that calls the triangle CFUNCTION doesn't agree with the CFUNCTION description I don't understand what the first 'one' value is doing there. The first parameter should be the x-coordinate of first point. My guess would be (to give filled triangles) I expect that you have ended up with different versions of the various sections of code. I would start by using the version of the CSUB which ships with the micromite code and work back from there. Note the different calling methods used. Jim VK7JH MMedit MMBasic Help |
||||
disco4now Guru Joined: 18/12/2014 Location: AustraliaPosts: 844 |
It looks like there is a different segment SUB which calls the triangle CFUNCTION which draws one triangle. It is called like this j=triangle(x1,y1,x2,y2,x,y,colour,colour) There is also a triangles CFUNCTION that writes multiple triangles and is called like this: j=triangles(1,xx0(),yy0(),xx1(),yy1(),xx2(),yy2(),tcol()) There is also another triangles CFUNCTION which preserves the background. It is called like this: i=triangles(nt, buff() , tcol(nt), xx0(nt), yy0(nt), xx1(nt), yy1(nt), xx2(nt), yy2(nt)) (See photo realist gauge thread) As Jim says I think you have code from different parts of the thread. I think your code needs this version of the segment SUB . Sub segment(x As integer, y As integer, size As integer, startradial As integer, endradial As integer, colour As integer) Local integer i,j,x1,x2,y1,y2,sr,er If startradial=endradial Then x2=Sin(Rad(startradial))*size + x y2=-Cos(Rad(startradial))*size + y Line x,y,x2,y2,,colour Else If startradial<endradial Then sr=startradial er=endradial Else er=startradial sr=endradial EndIf For i=sr+stepsize To er Step stepsize x2=Sin(Rad(i))*size + x y2=-Cos(Rad(i))*size + y x1=Sin(Rad(i-stepsize))*size + x y1=-Cos(Rad(i-stepsize))*size + y j=triangle(x1,y1,x2,y2,x,y,colour,colour) Next i EndIf End Sub Latest F4 Latest H7 |
||||
Print this page |