![]() |
Forum Index : Microcontroller and PC projects : Blit and Gauges
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks Gerry, the flicker is greatly reduced However I'#m still getting the static needle (as well as the moving needle) at the 12 o'clock position after the needle has completed one complete rotation the relevant section of code is (the only bit I removed is the get time bit to display the time) [code]getlimits(x, y, w, h) blit read #1, x, y, w, h '**********************Start of Main Program********************************** 'Direction pointer test for bb = 1 to 360 'so I can see the pointer move one complete revolution pause 10 'delay of 10mS so I can see the pointer steps heading = heading+1 'increment the heading 1 degree clockwise drawpointer(heading) 'draw the pointer print bb 'so I can see how many times the pointer moves before it crashes next bb 'End of direction pointer test LOOP End[/code] |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10189 |
There is no "DO" at the top of the main program. If it is above the getlimits call it is in the wrong place |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Sorry Peter I forgot to paste the "DO" (I cut and pasted and missed the DO*) It is in there [code]getlimits(x, y, w, h) blit read #1, x, y, w, h '**********************Start of Main Program********************************** DO 'Direction pointer test for bb = 1 to 360 'so I can see the pointer move one complete revolution pause 10 'delay of 10mS so I can see the pointer steps heading = heading+1 'increment the heading 1 degree clockwise drawpointer(heading) 'draw the pointer print bb 'so I can see how many times the pointer moves before it crashes next bb 'End of direction pointer test LOOP End[code] |
||||
GoodToGo!![]() Senior Member ![]() Joined: 23/04/2017 Location: AustraliaPosts: 188 |
Out of interest, what happens if you change the for bb = 1 to 360 line to for bb = 1 to 720? Does the pointer get erased on the first loop around? Cheers, GTG! ![]() ...... Don't worry mate, it'll be GoodToGo! |
||||
GoodToGo!![]() Senior Member ![]() Joined: 23/04/2017 Location: AustraliaPosts: 188 |
Or, maybe change it to for bb = 0 to 360? GTG! ![]() ...... Don't worry mate, it'll be GoodToGo! |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1000 |
Hi Lewis, Not sure why yours does not work. Here is basically your code that seems to work for me. See what it does for you. option explicit option default none CLS const Y_top = 0 'Y coordinate of top of the image file on the screen const X_left = 267 'X coordinate of left of the image file on the screen const Y_point = 130 'Y coordinate of the centre of the pointer relative to the image top const X_point = 110 'X coordinate of the centre of the pointer relative to the image left dim integer nt=1 'Number of triangles used to define the pointer dim integer ptr(5)=(-5,0, 5,0, 0,-60) ' define size of the pointers DIM INTEGER pcolour=(rgb(RED)) 'define the colour of the pointer DIM float heading const pivot=7 'diameter in pixels of the fulcrum of the pointer ' ' Global Variable definitions ' dim integer b dim integer xx0(nt),yy0(nt),xx1(nt),yy1(nt),xx2(nt),yy2(nt),tcol(nt) dim integer x,y,w,h cls rgb(white) getlimits(x, y, w, h) blit read #1, x, y, w, h do ' Main program for b = 1 to 360 'so I can see the pointer move one complete revolution pause 10 'delay of 100mS so I can see the pointer steps heading = heading+1 'increment the heading 1 degree clockwise drawpointer(heading) 'draw the pointer 'print b 'so I can see how many times the pointer moves before it crashes next b loop end sub getlimits(x as integer, y as integer, w as integer, h as integer) Local integer i,max_x=0,min_x=MM.HRES,max_y=0,min_y=MM.VRES for i=0 to nt-1 if(xx0(i)>max_x)then max_x=xx0(i) if(xx1(i)>max_x)then max_x=xx1(i) if(xx2(i)>max_x)then max_x=xx2(i) if(xx0(i)<min_x)then min_x=xx0(i) if(xx1(i)<min_x)then min_x=xx1(i) if(xx2(i)<min_x)then min_x=xx2(i) if(yy0(i)>max_y)then max_y=yy0(i) if(yy1(i)>max_y)then max_y=yy1(i) if(yy2(i)>max_y)then max_y=yy2(i) if(yy0(i)<min_y)then min_y=yy0(i) if(yy1(i)<min_y)then min_y=yy1(i) if(yy2(i)<min_y)then min_y=yy2(i) next i x=min_x y=min_y w=max_x-min_x+1 h=max_y-min_y+1 end sub sub rotatetriangle(n as integer, col as integer, angle as float, x as integer, y as integer, x0 as integer, y0 as integer, x1 as integer, y1 as integer, x2 as integer, y2 as integer) local float sine=sin(rad(angle)),cosine=cos(rad(angle)) local integer x0a,y0a,x1a,y1a,x2a,y2a x0a= x0*cosine - y0 * sine + x y0a= y0*cosine + x0 * sine + y x1a= x1*cosine - y1 * sine + x y1a= y1*cosine + x1 * sine + y x2a= x2*cosine - y2 * sine + x y2a= y2*cosine + x2 * sine + y xx0(n)=x0a yy0(n)=y0a xx1(n)=x1a yy1(n)=y1a xx2(n)=x2a yy2(n)=y2a tcol(n)=col end sub Sub drawpointer(angle as float, offset as integer) local integer last_x, last_y, last_w, last_h, i for i=0 to nt-1 'rotate the pointer into the drawing array for each triangle rotatetriangle(i,pcolour,angle,X_point+X_left,Y_point+Y_top,ptr(0),ptr(1),ptr(2),ptr(3),ptr(4),ptr(5)) NEXT i last_x=x: last_y=y: last_w=w: last_h=h getlimits(x, y, w, h) blit WRITE #1, last_x, last_y, last_w, last_h 'update old rectangle with saved data blit close #1 'free buffer blit read #1, x, y, w, h 'save the new rectangle to memory local integer k do k=getscanline() loop while (k>200 AND k<350) for i=0 to nt-1 'write new triangle for each triangle triangle xx0(i), yy0(i)+offset, xx1(i), yy1(i)+offset, xx2(i), yy2(i)+offset, tcol(i),tcol(i) NEXT i drawpivot(offset) End Sub sub drawpivot(offset as integer) 'put anything you like here to draw the fulcrum as you wish circle 377,130,pivot,0,,,rgb(54,54,54) end sub Latest F4 Latest H7 FotS |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Hmm I honestly don't know why it's not doing the same on mine When it gets to the the end of the FOR NEXT loop and restarts the loop the pointer stays on the screen at the 12 o'clock position I've enclosed my full code here. you might need to comment out the displaypicture lines and temp and humidity Other than that it should run Lewis 2017-08-17_205323_weather2-test.zip EDIT: GoodToGo good idea but it rotates completely 2 times then draws the pointer at 12 o'clock before it restarts the loop |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Hi Lewis, In your submitted code (i.e. the post before this one), you have the 'Direction pointer test' as: for bb = 0 to 720 It may be nothing (I haven't looked at any more of the code) BUT what if you change it to: for bb = 1 to 720 Give it a try . . . ![]() WW EDIT: Sorry - see GTG has suggested this already. So did you try starting loop at 1? |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1000 |
Hi Lewis, The problem is that Global variable y is being used to remember where the background is stored and also in the DayOfWeek function. Everytime DayOfWeek() is used it will upset its memory of where the blit command put the data. Add this line to make the variables in the DayOfweek() local LOCAL INTEGER a,m,y Function DayOfWeek(year AS INTEGER, month AS INTEGER, day AS INTEGER) AS INTEGER 'Day of Week Function local integer a,m,y a = Int((14-month)/12) m = month + 12*a - 2 y = year - a DayOfWeek = (day + y + Int(y/4)-Int(y/100)+Int(y/400)+Int(31*m/12)) Mod 7 End Function A tricky one, Regards Gerry Latest F4 Latest H7 FotS |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Gerry that's perfect thank you so much. I'd never have worked that out myself. One last question speaking of the DayOfWeek function Have you any idea why the day of the week doesn't change on a new day? It only calls the day of the week once and never changes day? I've got it to call the dow every second but I can't understand why it doesn't pick up new days |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1000 |
Hi Lewis, When you update the day of week you pass the variables Year,Month and Date. i.e Text 415,235, DOW$(DayOfWeek(Year, Month, Day)), LM, 1, 2, RGB(BLACK), RGB(WHITE) 'Print the Day of week The bit of code that sets these variables in about line 66 is only ever run at startup and not included in the main loops so never changes. Year=Val(Mid$(Date$,7,4)):Month=Val(Mid$(Date$,4,2)):Day=Val(Mid$(Date$,1,2)) This needs to also be included in the UpDateTime sub so it gets updated as the program loops around. ' Interrupt service routine Sub UpDateTime ' called by 1 second interrupt from SetTick Local hrs,mins,secs,day,month,year hrs = Val(left$(Time$,2)) mins = Val(Mid$(Time$,4,2)) secs = Val(right$(Time$,2)) DOW$(0)="Sunday":DOW$(1)="Monday":DOW$(2)="Tuesday":DOW$(3)= "Wednesday":DOW$(4)="Thursday":DOW$(5)="Friday":DOW$(6)="Saturday" ' Day of the week ' Get the current time, extract the minutes component If secs = 0 Then MinFlag = 1 Else MinFlag = 0 EndIf ' Get the current time, test for 00:00:00 If hrs = 2 And mins = 0 And secs = 1 Then RTC GETTIME EODFlag = 1 Else EODFlag = 0 EndIf Year=Val(Mid$(Date$,7,4)):Month=Val(Mid$(Date$,4,2)):Day=Val(Mid$(Date$,1,2)) NewDataFlag = 1 ' set to indicate fresh data End Sub Latest F4 Latest H7 FotS |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thanks Gerry, I've changed that now, just have to wait 16 hours to see it change ![]() |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1000 |
That's an evil number of posts you have there at the moment Lewis! This wont make much sense once you post again. Latest F4 Latest H7 FotS |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
I like the Chinese use of '666' better. :) Microblocks. Build with logic. |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Hi Lewis, Can you confirm what size TFT you are using there please! I have tried your code on an E100 with a 4.3" and a 5" TFT and neither work as expected. ![]() I obviously have the RD pin configured in the OPTION LCDPANEL configuration, and have tried 5 and 5A too. Currently no 7" here to try with. Thanks . . . |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
It's a 7 inch TFT Can't see why it wouldn't work as far as I know they are identical other than the screen size |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Gerry can you try the following code instead of the "test rotate FOR/NEXT loop" please? [code]Heading = 100 'MAKE THE HEADING 100° drawpointer(heading)[/code] With any value OTHER THAN NEAR 180 (pointing South) the needle is nice and stable With the heading=180 or anywhere near it then the "point bit" of the needle dissapears any ideas? |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2932 |
Lewis, You have a lot of TEXT commands; some clearing the relevant 'area', and some displaying data. It is likely to be a TEXT statement that is just 'over' the area of the tip of the pointer. What are the co-ordinates of the centre of the pointer; and also the radius (in terms of pixels). I will then look for a 'suspect' TEXT that might be the cause. Then simply comment out the TEXT statements that are close to the dial. Hope that makes sense . . . WW |
||||
Alastair Senior Member ![]() Joined: 03/04/2017 Location: AustraliaPosts: 161 |
Lew, Have you checked the pinout on the screen. There are a couple of variants. One will connect direct to the MM with an inline ribbon the other you need to 'çustomise'? My first 7" was fine the other, from the same source, was different. They replaced it because I had specified a particular one. I ended up with the extra one as they did not want it back. cheers Cheers, Alastair |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
WW it makes perfect sense, that was my thought also which is why I moved the "time readout" down to the bottom of the screen to test if that was the problem it's directly under the 6pm position - but it made no difference The pointer is 94 pixels long and the center of it I'm not certain The fulcrum is circle 397,110 [quote]relevent section of code[/quote] dim integer ptr(5)=(-7,0, 7,0, 0,-94) ' define size of the pointers sub drawpivot(offset as integer) 'put anything you like here to draw the fulcrum as you wish circle 397,110,pivot,0,,,rgb(54,54,54) end sub I'm also slowly getting rid of the text on the screen and trying to figure out how to use numberbox to display the values for the weather displays ![]() |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |