ESP8266 tachometer/alternator tach

Place your projects here
Post Reply
Zim
Posts: 280
Joined: Mon Feb 08, 2021 9:15 pm
Has thanked: 253 times
Been thanked: 128 times

ESP8266 tachometer/alternator tach

Post by Zim »

tach.jpg
2021-02-10 18_26_36-Forum - Annex WiFI RDS — Mozilla Firefox.jpg

Code: [Local Link Removed for Guests]

'Zim's Tach with last used mode recall
onHtmlreload initial_page
gosub initial_page
timer0 1000, refresh_vars   
wait

initial_page:
'file.save "/plset.txt", str$(5)   'XXXXXXXXXXXXXXXXXXXX   uncheck this for the first run so it creates a memory txt file 
cls
PIN.MODE 5, input
COUNTER.SETUP 1, 5, 1
uS = 0
rpm = 0
pulses = val(file.read$("/plset.txt")) 'sets to last setting used
dropd$ = "background-color:lightblue;text-align:center;width:55px;height:55px;box-shadow: 0px 0px black;font-size:24;font-weight:bold"
exitb$ = "background-color:red;text-align:center;width:165px;height:55px;box-shadow: 0px 0px black;font-size:24;font-weight:bold;"
txtb$ = "background-color:black;text-align:center;width:55px;height:55px;font-size:40; color:white; border-radius:8px; font-weight:bold"
jsexternal "/gauge.min.js" ' load javascript library for gauges
pause 500 ' gives time to the browser to import the library

A$ = ""
A$ = A$ + |<style> body { background-color: black; }</style>| ' this defines the back color of the page (body)
A$ = A$ + |<div align="center" style="background-color:black;">| ' this permit to define the back color and the alignment (<div>)
A$ = A$ + |<canvas data-type="radial-gauge"|
A$ = A$ + |    data-width="335"|
A$ = A$ + |    data-height="335"|
A$ = A$ + |    data-title="RPM"|
A$ = A$ + |    data-units="X100"|
A$ = A$ + |    data-min-value="0"|
A$ = A$ + |    data-max-value="70"|
A$ = A$ + |    data-major-ticks="0,,10,,20,,30,,40,,50,,60,,70"|
A$ = A$ + |    data-minor-ticks="5"|
A$ = A$ + |    data-stroke-ticks="true"|
A$ = A$ + |    data-highlights='[|
A$ = A$ + |    {"from": 0, "to": 70, "color": "rgba(192,192,192,.2)"}|
A$ = A$ + |    ]'|
A$ = A$ + |    data-color-plate="#fff"|
A$ = A$ + |    data-color-numbers="#000000"|
A$ = A$ + |    data-border-shadow-width="8"|
A$ = A$ + |    data-borders="true"|
A$ = A$ + |    data-needle-type="arrow"|
A$ = A$ + |    data-needle-width="4"|
A$ = A$ + |    data-needle-circle-size="8"|
A$ = A$ + |    data-needle-circle-outer="true"|
A$ = A$ + |    data-needle-circle-inner="false"|
A$ = A$ + |    data-animation-duration="500"|
A$ = A$ + |    data-animation-rule="linear"|
A$ = A$ + |    data-color-border-outer="#333"|
A$ = A$ + |    data-color-border-outer-end="#111"|
A$ = A$ + |    data-color-border-middle="#FF0000"|
A$ = A$ + |    data-color-border-middle-end="#111"|
A$ = A$ + |    data-color-border-inner="#222"|
A$ = A$ + |    data-color-border-inner-end="#333"|
A$ = A$ + |    data-color-needle-circle-outer="#333"|
A$ = A$ + |    data-color-needle-circle-outer-end="#111"|
A$ = A$ + |    data-color-needle-circle-inner="#111"|
A$ = A$ + |    data-color-needle-circle-inner-end="#222"|
A$ = A$ + |    data-animation-duration="100"|
A$ = A$ + |    data-font-numbers-size="32"|
A$ = A$ + |    data-value-box="y"|   'gives a text box
A$ = A$ + |    data-var="rpm"|   ' this is where the variable is defined
A$ = A$ + |    ></canvas></div>|
A$ = A$ + |<table align='center' width='340'>|
A$ = A$ + |<center><th>|
A$ = A$ + textbox$(pulses, "txt2")
A$ = A$ + cssid$("txt2", txtb$)
A$ = A$ + |</th></center><center><th>|
A$ = A$ + |<p><font color = 'white', font size = '5'>Pulses Per  Revolution</font></p>|
A$ = A$ + |</th></center></table>|
A$ = A$ + |<center>|
A$ = A$ + button$("1P",pulse1,"but0")
A$ = A$ + cssid$("but0" , dropd$)
A$ = A$ + button$("2P",pulse2,"but1")
A$ = A$ + cssid$("but1" , dropd$)
A$ = A$ + button$("3P",pulse3,"but2")
A$ = A$ + cssid$("but2" , dropd$)
A$ = A$ + button$("4P",pulse4,"but3")
A$ = A$ + cssid$("but3" , dropd$)
A$ = A$ + button$("5P",pulse5,"but4")
A$ = A$ + cssid$("but4" , dropd$)
A$ = A$ + button$("6P",pulse6,"but5")
A$ = A$ + cssid$("but5" , dropd$)
A$ = A$ + |</center><center><br><br>|
A$ = A$ + button$("Refresh",initial_page,"but7")
A$ = A$ + cssid$("but7" ,exitb$ & "background-color:lightblue")
A$ = A$ + button$("Exit",exitt,"but6")
A$ = A$ + cssid$("but6" , exitb$)
A$ = A$ + |</center>|
html A$
jscall "initGauges();"  'force the initialisation of all the gauges
return

refresh_vars:
'wlog uS              ' alive check
uS = COUNTER.PERIOD(1)
if uS = 0 then uS = 1          'stops a math error
rpm = 10000 / uS / pulses * 60       '10000 instead of 1000000 cause its X100 tach
if rpm > 50000 then rpm = 0        'stops a error
COUNTER.RESET 1               'allows needle to zero with no signal
refresh
return

pulse1:
pulses = 1
file.save "/plset.txt", str$(1)
refresh
return

pulse2:
pulses = 2
file.save "/plset.txt", str$(2)
refresh
return

pulse3:
pulses = 3
file.save "/plset.txt", str$(3)
refresh
return

pulse4:
pulses = 4
file.save "/plset.txt", str$(4)
refresh
return

pulse5:
pulses = 5
file.save "/plset.txt", str$(5)
refresh
return

pulse6:
pulses = 6
file.save "/plset.txt", str$(6)
refresh
return

exitt:
cls
wait
gauge.min.js.gz
You do not have the required permissions to view the files attached to this post.
Post Reply