Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 06:16 04 May 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 : Maximite Simulator

Author Message
jincamty

Newbie

Joined: 10/07/2011
Location: New Zealand
Posts: 21
Posted: 12:49pm 19 Apr 2017
Copy link to clipboard 
Print this post

Hi Guys,

I am trying to modify some code to create horizontal bar graphs to measure
temperature, pressure and voltage etc.

I have been playing with GRAPH.BAS in the MMBasic library which gives an example
of a vertical bar graph, but I need to make it horizontal.

I have no idea what I'm doing so it's a matter of trial and error.

Is there some way I can sit in comfort and modify the code without having to
use the CGCOLORMAX2 ?

Cheers Cam.
 
Justplayin

Guru

Joined: 31/01/2014
Location: United States
Posts: 309
Posted: 12:59pm 19 Apr 2017
Copy link to clipboard 
Print this post

TassyJim's MMEdit is the best tool for editing code on both Maximites and Micromites. It does not simulate a 'mite but it does allow you the easy of using a Windows program to edit/copy/paste and save your programs and quickly and easily transfer them to the 'mite. Plus the Crunch feature is great for removing blank line and comments went the code is sent the the 'mite helping to free up memory.

--Curtis
I am not a Mad Scientist...  It makes me happy inventing new ways to take over the world!!
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1097
Posted: 06:31pm 20 Apr 2017
Copy link to clipboard 
Print this post

@jimcanty

Hi Mate,

As suggested above, MMEdit is a good way to go to edit programs.

The code below is for a horizontal graph showing some sample voltages and currents
over a 6 hour period updated every 2 seconds - it's just an example of how you might draw a running horizontal graph.

I use a similar display in my caravan battery monitor program.

Hope this helps,
Cheers,
Doug.



''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' vangraph.bas '

Mode 3,7 ' 8 colour mode white printing
Colour 7,0 ' confirming white on black

' Call subroutine to display all static data
DisplayStatic ' all the labels, borders etc.

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Main program loop
'
Main:
Do

AverageBV = 12.8
AverageSV = 18.5
AverageIC = 15.25
AverageLC = 12.8
AverageBC = AverageIC - AverageLC

' Now paint out running graph
' - first work out the current minute hour combo in minutes
rg_mins = (((Val(Mid$(Time$,1,2)) Mod 6)*60))+(Val(Mid$(Time$,4,2)))
rg_mins = rg_mins + 30 ' offset to start of graph
rg_abv = 413 - Int((AverageBV-7.5) * 20)
if rg_abv > 413 then rg_abv = 413
rg_asv = 413 - Int((AverageSV-7.5) * 20)
if rg_asv > 413 then rg_asv = 413
if rg_asv < 163 then rg_asv = 163
rg_aic = 413 - Int(AverageIC * 5)
rg_alc = 413 - Int(AverageLC * 5)
If (Sgn(AverageBC) = +1) Then
rg_abc = 413 - Int(AverageBC * 5)
Else
rg_abc = 413 + Int(AverageBC * 5)
EndIf

For rg_y = 163 To 413 Step 1
If rg_abc = rg_y Then
If (Sgn(AverageBC) = +1) Then
Pixel(rg_mins,rg_y) = 2 ' 2=green
Else
Pixel(rg_mins,rg_y) = 4 ' 4=red
EndIf
Else
Pixel(rg_mins,rg_y) = 0 ' 0=black
EndIf
If rg_abv = rg_y Then
Pixel(rg_mins,rg_y) = 7 ' 7=white
EndIf
If rg_asv = rg_y Then
Pixel(rg_mins,rg_y) = 1 ' 1=blue
EndIf
If rg_aic = rg_y Then
Pixel(rg_mins,rg_y) = 6 ' 6=yellow
EndIf
If rg_alc = rg_y Then
Pixel(rg_mins,rg_y) = 5 ' 5=magenta
EndIf
Next rg_y
For rg_y = 163 To 413 Step 1
Pixel(rg_mins+1,rg_y) = 0
Pixel(rg_mins+2,rg_y) = 0
Pixel(rg_mins+3,rg_y) = 0
Next rg_y

pause 2000
loop
' End of main program loop
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Set up terminal display with static data (field names etc.)
Sub DisplayStatic
Cls
Colour 7,0
volts=20
amps = 50
For ry =163 to 403 step 10
Print @(400,ry)Format$(amps,"%2.0fA")
amps=amps-2
next ry
For ry =163 to 403 step 20
Print @(2,ry)Format$(volts,"%2.0fV")
volts=volts-1
next ry
Line(29,163)-(29,413)
Line(391,163)-(391,413)
For yrg = 163 To 413 Step 10 'major ticks both sides
Pixel(28,yrg)=7
Pixel(27,yrg)=7
Pixel(392,yrg)=7
Pixel(393,yrg)=7
Next yrg
For yrg = 163 To 413 Step 20 'minor ticks on volts side
Pixel(27,yrg)=7
Next yrg

Line(30,414)-(390,414)
For xrg = 30 To 390 Step 5
Pixel(xrg,415)=7
Next xrg
For xrg = 30 To 390 Step 15
Pixel(xrg,415)=7
Pixel(xrg,416)=7
Next xrg
For xrg = 30 To 390 Step 30
Pixel(xrg,415)=7
Pixel(xrg,416)=7
Pixel(xrg,417)=7
Next xrg
For xrg = 30 To 390 Step 60
Pixel(xrg,415)=7
Pixel(xrg,416)=7
Pixel(xrg,417)=7
Pixel(xrg,418)=7
Next xrg
x_label=1
for bx = 88 to 388 step 60
Print @(bx,418)STr$(x_label) ' running graph x labels - hours -
x_label=x_label+1 ' so we display a running 6 hour window
next bx
End Sub


... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
jincamty

Newbie

Joined: 10/07/2011
Location: New Zealand
Posts: 21
Posted: 07:10pm 20 Apr 2017
Copy link to clipboard 
Print this post

Wow, Thanks Doug.

I have no idea how to comprehend that. I can only cope with 4 or 5 lines at a time. (extreme novice) :-)
This is what I came up with. It will display the water temperature with a sliding bar underneath.
Scaling and positioning take a bit of trial and error

line number
Font#2,1,0
Print@(20,30) "WATER" DS18B20(15)
barval = DS18B20(15) 'store temperature sensor to barval
barval = barval * 1.2 'scale value to fit bar graph length
col=2 'set color
If barval > 120 then col=4 'bar changes color after certain value
Line (225,50)-((225-barval,80),7,bf 'the numbers position and size the bar, (7 is the background color)
Line (20,50)-((barval+20),80),(col),bf
goto line number

That took me all night :-)

Cheers Cam.

Edited by jincamty 2017-04-22
 
jincamty

Newbie

Joined: 10/07/2011
Location: New Zealand
Posts: 21
Posted: 08:10pm 20 Apr 2017
Copy link to clipboard 
Print this post

Sorry that wasn't quite right (edited)Edited by jincamty 2017-04-22
 
jincamty

Newbie

Joined: 10/07/2011
Location: New Zealand
Posts: 21
Posted: 09:47pm 20 Apr 2017
Copy link to clipboard 
Print this post

That's not right either
Should read.

Line ((barval+20),50)-(160,80),7,bf
Line (20,50)-((barval+20),80),(col),bf

The second line creates the bar from the temperature measurement..
The first line replaces the bar with the background when the measurement drops.

Cheers Cam.
 
Print this page


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

© JAQ Software 2024