![]() |
Forum Index : Microcontroller and PC projects : Newie got a few questions
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3315 |
>Case "#1" 'look for the first "#"? because every UDP packet ends with # No--because each UDP packet is tagged with an initial "#" plus digit (1,2, etc.) so that it can be picked out. You initially ended each packet with ",#"--but with this code it should be ",#," so that the FIELD$ command can find the lone comma-separated "#" at the end of the UDP packet. (Actually, some earlier code I had looked for the terminating "#", but this code just relies on there being 25 valid data fields to pick out.) >Print i%;" ";a$(i%) 'print the fields received maybe? Yes. The first of the UDP packets which you set up on the ESP32 contains 25 data fields between the "#1" and the terminating "#", starting with field number 2 (because "#1" is field number 1). These are put into the string array a$() at positions a$(1) through a$(25). Then the second UDP packet has its fields broken out and put into the array similarly, going into array positions a$(26) through a$(50). PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
deleted Edited 2020-12-21 23:03 by lew247 |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Can you do this? and if not why not? if a$(1) = "not found" then end sub or am I just doing it wrong so it jumps out of the subroutine if bad data is received Edited 2020-12-22 02:37 by lew247 |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3315 |
Need to see more of the code to determine the best way to do this. UDP receive aa$,b$,c% If c%>0 Then tag$=Mid$(aa$,1,2) Select Case tag$ Case "#1": For i%=1 To 25: a$(i%)=Field$(aa$,i%+1): Next i% ' LISTFIELDS Case "#2": For i%=1 To 25: a$(i%+25)=Field$(aa$,i%+1): Next i% For i%=1 To 50: Print i%;" ";a$(i%): Next i% End Select end if In the above code, for instance, "If c%>0 Then" prevents the following code from executing when there has been no UDP message received. Perhaps you want to put the remainder of your code after "Case "#2":" so that you only execute it when you have received a pair of new UDP messages. Or set a flag after that statement, and only redraw your screen when the flag is set. Otherwise, it's possible that you are talking about a case where the first UDP message is this: #1*,,Rain Likely,7.9,979.9,falling,95,6.0,SSE,null,11.0,null,6.0,6.24,1.74,Rain Likely,rainy,10.0,7.0,80,chance-rain,rain,Rain Possible,possibly-rainy-day,9.0,6.0,# In that case, a$(1) will be an empty string, "". If that is the case, you could test IF a$(1)="" THEN (instead of ="not found"--unless the UDP message actually contains the text "not found"). ~ Edited 2020-12-22 03:25 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Sorry not quite clear Each data element sent via UDP can contain valid data "not found" or "" I need a way to end the sub or skip to the next UDP receive if either of those happen Edited 2020-12-22 03:32 by lew247 |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3315 |
If a$(1) actually contains the text, "not found", then what you suggested would work: IF a$(1)="not found" then EXIT SUB PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
It does contain that text but unfortunately it doesn't exit the sub, I thought it might not work or I was doing it wrong |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Lance, sent you a message with the full code so you can see what I meant better |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Anyone got any suggestions as to why this doesn't change the day or date on the display? I've tried it without dow1$ = DOW$(DayOfWeek(YEAR,MONTH,DAY)) 'day of week today in the DO loop but it makes no difference The day and date never changes DOW$(0)="Sunday":DOW$(1)="Monday":DOW$(2)="Tuesday":DOW$(3)="Wednesday":DOW$(4)="Thursday":DOW$(5)="Friday":DOW$(6)="Saturday" Year=Val(Mid$(Date$,7,4)):Month=Val(Mid$(Date$,4,2)):Day=Val(Mid$(Date$,1,2)) dow1$ = DOW$(DayOfWeek(YEAR,MONTH,DAY)) 'day of week today DO dow1$ = DOW$(DayOfWeek(YEAR,MONTH,DAY)) 'day of week today IF Day <> OldDay then 'day has changed update the display to reflect this Text mm.hres-180 ,MM.VRES/70, DATE$, LT,4, 1, RGB(WHITE),RGB(162,160,160) 'Date Text 15,MM.VRES/70, DOW$(DayOfWeek(YEAR,MONTH,DAY)), LT,4, 1, RGB(WHITE),RGB(162,160,160) 'Day of the week END IF OldDay = Day Loop UDP close END |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3315 |
Assuming this is test code, place "Day=Val(Mid$(Date$,1,2))" after "OldDay = Day" within the loop. Better: place "OldDay = Day" inside the IF statement, and "Day=Val(Mid$(Date$,1,2))" outside it. If it's not test code, why is there a never-ending loop? Edited 2021-01-02 23:58 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
This is the full loop I thought doing it this way then it would always be checking if the day was a new day or not That's why I put the OldDay = Day after the If/Then statement DO dow1$ = DOW$(DayOfWeek(YEAR,MONTH,DAY)) 'day of week today ss$=mid$(time$,7,2) 'do something here every second if needed IF ss$ <> sec1$ THEN sec1$ = ss$ END IF ' print time$ ' so I can see this working IF Day <> OldDay then 'day has changed update the display to reflect this Text mm.hres-180 ,MM.VRES/70, DATE$, LT,4, 1, RGB(WHITE),RGB(162,160,160) 'Date Text 15,MM.VRES/70, DOW$(DayOfWeek(YEAR,MONTH,DAY)), LT,4, 1, RGB(WHITE),RGB(162,160,160) 'Day of the week th$ = tempnow$ tl$ = tempnow$ gustnow2 = 0 END IF UDP receive aa$,b$,c% IF c%>0 Then tag$=Mid$(aa$,1,2) Select Case tag$ Case "#1": For i%=1 To 20: a$(i%)=Field$(aa$,i%+1): Next i% ' LISTFIELDS Case "#2": For i%=1 To 20: a$(i%+20)=Field$(aa$,i%+1): Next i% Case "#3": For i%=1 To 10: a$(i%+40)=Field$(aa$,i%+1): Next i% For i%=1 To 60: Print i%;" ";a$(i%): Next i% DECODE DAYSUB UPDATE END Select END IF OldDay = Day Loop UDP close END |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3315 |
But you only set "Day=Val(Mid$(Date$,1,2))" outside the loop, so it never changes within it. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Ah, I thought it would always know the date the same as it always knows the time |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3315 |
It does always know the date the same as it knows the time, but "Day" is a variable which you have defined, so you need to continually refresh it from the Date$ function. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thank you ![]() |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
I'm pulling what little hair I have left out on this one I've completely redone my code so it's all processed with a Pi 3+ now instead of a Zero and Esp32 I've got everything "I think" perfect other than this one thing It's meant to place an image of the current moon phase on the screen BUT it's not working It only places Image 1.bmp on the screen I've tried everything I can think of to try and figure out why it isn't working Including reading the manual again and as far as I can see I have it correct and it should work The current moonage value is 23.97518097 so it "should" select image 24.bmp Can anyone see the stupid mistake I've obviously made? Sub MoonImage 'Get the correct moon image for today Select Case moonage Case = 0 Load image "0.bmp",910,270 'weather moon icon Case IS > 0, IS <= 1 Load image "1.bmp",910,270 'weather moon icon Case IS > 1, IS <= 2 Load image "2.bmp",910,270 'weather moon icon Case IS > 2, IS <= 3 Load image "3.bmp",910,270 'weather moon icon Case IS > 3, IS <= 4 Load image "4.bmp",910,270 'weather moon icon Case IS > 4, IS <= 5 Load image "5.bmp",910,270 'weather moon icon Case IS > 5, IS <= 6 Load image "6.bmp",910,270 'weather moon icon Case IS > 6, IS <= 7 Load image "7.bmp",910,270 'weather moon icon Case IS > 7, IS <= 8 Load image "8.bmp",910,270 'weather moon icon Case IS > 8, IS <= 9 Load image "9.bmp",910,270 'weather moon icon Case IS > 9, IS <= 10 Load image "10.bmp",910,270 'weather moon icon Case IS > 10, IS <= 11 Load image "11.bmp",910,270 'weather moon icon Case IS > 11, IS <= 12 Load image "12.bmp",910,270 'weather moon icon Case IS > 12, IS <=13 Load image "13.bmp",910,270 'weather moon icon Case IS > 13, IS <= 14 Load image "14.bmp",910,270 'weather moon icon Case IS > 14, IS <= 15 Load image "15.bmp",910,270 'weather moon icon Case IS > 15, IS <= 16 Load image "16.bmp",910,270 'weather moon icon Case IS > 16, IS <= 17 Load image "17.bmp",910,270 'weather moon icon Case IS > 17, IS <= 18 Load image "18.bmp",910,270 'weather moon icon Case IS > 18, IS <= 19 Load image "9.bmp",910,270 'weather moon icon Case IS > 19, IS <= 20 Load image "20.bmp",910,270 'weather moon icon Case IS > 20, IS <= 21 Load image "21.bmp",910,270 'weather moon icon Case IS > 21, IS <= 22 Load image "22.bmp",910,270 'weather moon icon Case IS > 22, IS <= 23 Load image "23.bmp",910,270 'weather moon icon Case IS > 23, IS <= 24 Load image "24.bmp",910,270 'weather moon icon Case IS > 24, IS <= 25 Load image "25.bmp",910,270 'weather moon icon Case IS > 25, IS <= 26 Load image "26.bmp",910,270 'weather moon icon Case IS > 26, IS <= 27 Load image "27.bmp",910,270 'weather moon icon Case IS > 27, IS <= 28 Load image "28.bmp",910,270 'weather moon icon Case IS > 28, IS <= 29 Load image "29.bmp",910,270 'weather moon icon Case IS > 29, IS <= 30 Load image "30.bmp",910,270 'weather moon icon END select print moonage , "Moonage" End sub |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3315 |
Which image are you getting? What's the result of your print statement? Can you replace the whole thing with this? dim string sImage sImage=str$(int(moonage+.5))+".bmp" Load image sImage,910,270 print moonage , "Moonage", sImage PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
The result of the print statement at this moment is 24.03748008 It's loading image 1.bmp What does sImage=str$(int(moonage+.5)) produce? I can't work out what it means (sorry) There are 30 images of the moon, titled 0.bmp to 30.bmp one for each moonpase as it appears example at this moment it should be ![]() but it's displaying ![]() |
||||
jirsoft![]() Guru ![]() Joined: 18/09/2020 Location: Czech RepublicPosts: 533 |
It's just rounding number to whole number and convert it to string (and then later add ".BMP" to it, so for example from moonage=3.72 will be sImage="4.BMP"), but simpler is (CINT(x) = INT(x + 0.5)): LOAD IMAGE STR$(CINT(moonage)) + ".BMP", 910, 270 Edited 2021-01-08 02:17 by jirsoft Jiri Napoleon Commander and SimplEd for CMM2 (GitHub), Â CMM2.fun |
||||
lew247![]() Guru ![]() Joined: 23/12/2015 Location: United KingdomPosts: 1702 |
Thank you both so much That works perfectly and I actually understand what it's doing as well now ![]() One final one and I really think that this is impossible as I'm stuck on V5.05.01 I have this outline of a compass is it possible to get the numbers around the outside to rotate to a given angle? It doesn't have to look like it's rotating, it can just move. ie if the angle was 45 then the letters moved around the circle 45 deg so N is in the E position and so on? Ideally I'd like to have NE, NW, SE, SW on there too but can't figure out how to get them on it I know it's possible with the CMM2 but I can't waste one of those for this project even if I did have one dim cx% = 785 dim cy% = 238 dim wid% = 105 dim ang! = 0.087266463 Circle mm.hres/2,mm.vres/4 + mm.vres/32,90,2,1,RGB(WHITE),RGB(134,174,230) 'Centre sub compass_rose cx%,cy%,wid% local a% for a% = 0 to 90 line (cx%+15)+(cos(a%*ang!)*(wid%*.85)),(cy%+15)-(sin(a%*ang!)*(wid%*.85)),(cx%+15)+(cos(a%*ang!)*(wid%*.9)),(cy%+15)-(sin(a%*ang!)*(wid%*.9)),,RGB(WHITE) next text cx%+9,cy%-wid%+5,"N",lt,4,1,RGB(BLACK),RGB(134,174,230)' text cx%+9,cy%+wid%+5,"S",lt,4,1,RGB(BLACK),RGB(134,174,230)' text cx%+wid%+8,cy%+4,"E",lt,4,1,RGB(BLACK),RGB(134,174,230)' text cx%-wid%+8,cy%+4,"W",lt,4,1,RGB(BLACK),RGB(134,174,230)' circle cx%+15,cy%+15,wid%-16 circle cx%+15,cy%+15,wid%-13 end sub This is what it's like now (I've left the centre of the compass out of the code above as this would stay in position and not move Edited 2021-01-08 02:41 by lew247 |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |