Forum > Embedded - AVR

How to run script on Lazarus

(1/2) > >>

microguy:
I am running Lazarus with Arduino. I am control LEDs and Servos with 40 buttons on Lazarus. They are working just fine. Now I want to know if there is a way we can use the script or something that we can tell which buttons to turn on or off LED or Servos. I am doing a lot of lights and servos for animations. I would like to have several scripts that I can select to run which it will tell which buttons to turn on or off and servos to move right or left or up or down.  Is there a sample where I can add script or something to command which buttons to turn on or off LEDs etc..

dseligo:
Do you program Arduino controller in Arduino app and connect to it through serial connection?
Or do you program Arduino controller with Lazarus and cross compile it to AVR?

I'll assume first one is the case. Lets assume you have ButtonA and ButtonB. When you press ButtonA, Lazarus sends command to Arduino and turn on LED01. When you press ButtonB, Lazarus sends command to Arduino and move Servo01.
And now you would like to configure that e.g. ButtonA send command to Arduino and move Servo01.
Could you show details how this look like?

I would suggest you different ini files or SQlite database where you would store different configurations and according to them, map button press to action.

Gustavo 'Gus' Carreno:
Hey microguy,

Let me see if I get this right.

You want a way to customize the actions performed by the Arduino when you press a button.
And, at the moment, what you have is a set of buttons that are connected to actions and all is hard coded in the app.

The way you solve this is not easy. Not easy to explain AND not easy to implement.

But here it goes...

First of all you need to create the complete set of procedures with all the SINGLE actions that you want to script.

So something like:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure LED(const Number; const On: Boolean = True); procedure Servo(const Number; const Position: Integer); 
And after that you need to create your OWN interpreter of a simple scripting language.

On some kind of UI you setup a script editor for each button.
For each button, you store a script and when the button is pressed you run that script.

A script would be something like this:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---LED0 ONWAIT 3LED1 OFFSERVO1 1000SERVO0 250
Now when you're parsing your script and encounter LED0 ON you call LED(0, True)
When you encounter SERVO0 1000 you call SERVO(0, 1000)
When you encounter WAIT 3 you call Sleep(3000)

When you get all this implemented and you feel it's solid you can then try to implement cycles.
After a while you'll miss them ;)

Am I making any sense?

Cheers,
Gus

Gustavo 'Gus' Carreno:
Hey microguy,

One last thing.

My suggestion of doing your own little scripting language comes from the fact that it would be overkill to embed any full blown scripting engine for such a simple usage.

But if you feel curious, there are integrations with Lua, just Google "Lua for Pascal OR Lazarus" and you'll get some good hits.

And there's the Pascal Script that is hosted on GitHub: https://github.com/remobjects/pascalscript.

I'm sure that other people will suggest more.

Cheers,
Gus

microguy:
dseligo,

It is the first one. I program the Arduino controller in Arduino app and connect to Lit through serial connection. When I press Button for LED01, Lazarus sends command to Arduino and turn on on LED01 same as botton for servo01, Lazarus sends command to Arduino and Servo01 move.

What I am trying to figure out how to record all the buttons in order. While I am on Lazaurus with Arduino. I was be able to do manual but I was hope to some kind of automatic or record to run it. I was not sure how to do this. I thought we could run script or maybe it is wrong word. Something that we can click name of list which we can create a small sub program that tell all the buttons and which one comes first like buttons10 to move sevos then button14 turn on LED14 and wait for next button16 servo16 finish moved then button14 LED goes off etc. 

I hope you understand what I am looking for. My english is not that great.

Navigation

[0] Message Index

[#] Next page

Go to full version