Controlling and Set...
 
Notifications
Clear all

Controlling and Setting Stored Values for a Dash

3 Posts
2 Users
0 Reactions
2,170 Views
(@athleteinaction)
New Member
Joined: 2 years ago
Posts: 1
Topic starter  

I am looking to set a stored value for use in a dash. Something like 'target laps' set by using a button or encoder on my wheel. I understand this concept https://github.com/SHWotever/SimHub/wiki/Javascript-Formula-Engine#storing-data-accross-formula-evaluations, and I am very familiar with JS. I cant understand how to relate using a button to execute JS.


   
Quote
(@dadima)
Active Member
Joined: 2 years ago
Posts: 12
 

Posted by: @athleteinaction

  • I cant understand how to relate using a button to execute JS.

Hi. I know it's been a while since this was post up. So how is it doing, are you able to get your button working? 

I am just a newbie to the js. However, to get your button working, u can upload a blank simhub sketch from the arduino tools inside simhub to your arduino, and use SHCustomProtocol.h file in the simhub installation folder to read your returning value from the js script. Please note that this js script you can just insert it in the simhub programs, in the binding panel. 

This is not a standard js, you might found some functions may not work in the normal js language. 

Just ensure you are returning a correct value(var) in the simhub binding panel. 

Use example 2 in the SHCustomProtocol.h as your reference. 

 

 

 


   
ReplyQuote
(@dadima)
Active Member
Joined: 2 years ago
Posts: 12
 

Posted by: @athleteinaction

I cant understand how to relate using a button to execute JS.

While re-thinking, the solution above works well when you want to control your arduino. But to use a button from arduino and send it to simhub, you will need to use a pro micro. When uploading the sketch, declare your buttons, then turn on the gamepad switch before upload the sketch. 

I don't think there are a straight forward step on how to make the button execute the js script. The default mechanism I think would be just reading the returning value(s) from the js script set inside simhub-and run your arduino. There would be a limited value that can be read from the button pressed. 

However, it might be possible to make use of the SHCustomProtocol.h to read values from the buttons pressed. 

1)declare all your button pins

2)set your button's pin as INPUT in the setup function

3)in the read funtion, read the returning values set in simhub binding(ensure to check the "use javascript" on top right corners. 

 

int lap = SerialReadStringUntil(';').toINT()

int rpm = SerialReadStringUntil('\n').toINT()

-here you can put the code to digitalWrite your button. 

4)in simhub binding, the js script need to return 2 values(lap and rpm). 

  • var lap = $prop(GameData.Laps) 
    var rpm=$prop(GameData.EngineRpms)
    
    if rpm>8500{rpm =1}
    else{rpm =0} 
    return (lap + ';' + rpm+) 

*this is just an example of synchronising js from simhub to arduino. 

 

 

This post was modified 12 months ago by dadima

   
ReplyQuote
Share: