Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:18 25 Nov 2024 Privacy Policy
Jump to

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 : Graphs using the new toys

Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 05:24pm 30 Aug 2023
Copy link to clipboard 
Print this post

I thought it worth a quick post showing how easy it is to graph data using some of the new bulk data math and memory commands in MMBasic V5.07.08b14

Task plot a sine wave

CLS
' we are going to plot it as a series of line segments not just points
' so create some arrays to hold the coordinates
Dim x1(MM.HRes-1),y1(MM.HRes-1),x2(MM.Hres-1),y2(MM.HRes-1)

' Fill the x1 and y1 arrays
For i=0 To MM.HRes-1
  x1(i)=i ' set the x coordinates
  y1(i)=Sin(Rad(i*2)) 'calculate the sinewave
Next

' now scale the y data to fit nicely in the display
' The display has 0,0 at top left so we want to invert the data and scale it sensibly
' so a sine value of +1 will plot at y=20
' a sine value of -1 will plot at MM.VRES-20
' all calculated in a single simple command
Math window y1(),MM.VRes-20,20,y1()

' We want to plot lines so each line starts a position y1 and ends at y2
' so create the y2 array with each element y2(i ) equal to y1(i-1) and x2(i)=x1(i-1)
Memory copy float Peek(varaddr y1(1)),Peek(varaddr y2(0)),MM.HRes-1
Memory copy float Peek(varaddr x1(1)),Peek(varaddr x2(0)),MM.HRes-1

'deal with the end points
y2(mm.hres-1)=y1(mm.hres-1)
x2(mm.hres-1)=x1(mm.hres-1)

' plot the line segments
Line x1(),y1(),x2(),y2()

'
Do
Loop

Edited 2023-08-31 03:35 by matherp
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2127
Posted: 06:03pm 30 Aug 2023
Copy link to clipboard 
Print this post

>
RUN
[18] Math window y1(),MM.VRes-20,20,y1()
Error : Syntax
>
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 06:04pm 30 Aug 2023
Copy link to clipboard 
Print this post

  Quote  MMBasic V5.07.08b14
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2127
Posted: 08:12pm 30 Aug 2023
Copy link to clipboard 
Print this post

With MMBasic V5.07.08b14
cool

 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 02:51am 08 Jun 2024
Copy link to clipboard 
Print this post

Hello all.
Is there a MATH function that does the equivalent of:

   For X = 0 to nbr
     y1(X) = y1(X+1)
   Next X

That is, it shuffles the values of a one dimensional array 1 X value to the left.
"nbr" might be the array's dimension-1.
This would allow a quicker plot of graphs that move 1 X value to the left each time period?
(One still has to insert the y1 value in y1(nbr)

Cheers,

Andrew
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 03:35am 08 Jun 2024
Copy link to clipboard 
Print this post

  Quote  Is there a MATH function that does the equivalent of:

  For X = 0 to nbr
    y1(X) = y1(X+1)
  Next X


memory copy float peek( varaddr fullday1())+8,peek( varaddr fullday1()),mm.hres


I usually couple it with
line graph xaxis(), fullday1(), rgb(yellow)

where xaxis(n) is 0 to mm.hres

Jim
VK7JH
MMedit   MMBasic Help
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 07:43am 08 Jun 2024
Copy link to clipboard 
Print this post

For Andrew
Simple temp/humidity chart
 ' simple temperature and humidity chart
 ' TassyJim June 2024
 DIM INTEGER xMax = MM.HRES-1 ' maximum chart x value
 DIM FLOAT dd1(xMax)
 DIM FLOAT dd2(xMax)
 DIM FLOAT dd3(xMax)
 DIM FLOAT scaled(xMax)
 DIM INTEGER xaxis(xMax)
 DIM FLOAT tmpr, hmid, tmax, tmin, hmax, hmin
 DIM INTEGER n
 FRAMEBUFFER CREATE
 
 FOR n = 0 TO xMax
   xaxis(n) = n
   dd1(n) = MM.VRES
   dd2(n) = MM.VRES
   dd3(n) = MM.VRES
 NEXT n
 n = 1
 BITBANG HUMID GP17, tmpr,hmid
 SETTICK 500,readtime
 
 DO
   
 LOOP
 
SUB readtime
 
 BITBANG HUMID GP17, tmpr,hmid
 dd1(xMax) = MM.HRES-tmpr/50*MM.HRES ' scaled 0 to 50 degrees
 dd2(xMax) = MM.HRES-hmid/100*MM.HRES ' scaled 0 to 100%
 IF MID$(TIME$,7,2)="00" THEN dd3(xMax) = MM.VRES-10 ' 1 min marker
 IF MID$(TIME$,4,2)="00" THEN dd3(xMax) = MM.VRES-20 ' hour marker
 
 'n = 1-n' uncomment this line to plot every second reading = 1 minute
 IF n THEN
   MEMORY COPY FLOAT PEEK( VARADDR dd1())+8,PEEK( VARADDR dd1()),xMax
   MEMORY COPY FLOAT PEEK( VARADDR dd2())+8,PEEK( VARADDR dd2()),xMax
   MEMORY COPY FLOAT PEEK( VARADDR dd3())+8,PEEK( VARADDR dd3()),xMax
   FRAMEBUFFER WRITE f
   CLS
   LINE GRAPH xaxis(), dd1(), RGB(YELLOW)
   LINE GRAPH xaxis(), dd2(), RGB(GREEN)
   LINE GRAPH xaxis(), dd3(), RGB(BLUE)
   
   TEXT 160, 50,STR$(tmpr,2,1)+"`C",cb,2,2, RGB(YELLOW)
   TEXT 160, 125,STR$(hmid,2,1)+"%",cb,2,2, RGB(GREEN)
   
   FRAMEBUFFER COPY f,n
   dd3(xMax) = MM.VRES
   
 ENDIF
END SUB
 


Jim
VK7JH
MMedit   MMBasic Help
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 07:52am 08 Jun 2024
Copy link to clipboard 
Print this post

Hi Jim,
Thanks for that - looks good. I'm on roast dinner duties so I'll play ASAP.

Cheers,

Andrew
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 847
Posted: 02:53am 09 Jun 2024
Copy link to clipboard 
Print this post

Hi Jim,
Thanks again. It is working well on a 4" ILI9488 LCD and I am now 'fiddling' to see if I understand what is going on. (I've not used FRAMEBUFFER before).

Regards,

Andrew
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6098
Posted: 06:04am 09 Jun 2024
Copy link to clipboard 
Print this post

You can ignore the framebuffer but there will be flickering without it.
VK7JH
MMedit   MMBasic Help
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024