How to send a number as a number or How to rule an LED

Claudi Cornaz claudi.c at fiberworld.nl
Sun Feb 6 11:01:25 CST 2011


Hi all,

Sorry for the wrong link I posted yesterday night. ( the arduino scetch instead of my demo stack)
It was late and I was tired from constantly testing and crashing. Killing LC about 100 times in a couple of hrs. So please forgive. 
(The stack wouldn't have worked anyway something sneaked in my stack.)

So this morning I noticed the cd I was working on suddenly stopped working and I have been struggeling ever since.

Well any way the stack works again, I guess, though I am a bit cautious.

You can download it from: http://dl.dropbox.com/u/13685013/Arduino%20Demo.livecode

I can now send data to the arduino to change the brightness of a led and I can send commands 
to change wether the arduino needs to send sensor data to LC and from which sensor. ( a potentiometer or a LDR)

This data is send at the full 10 bits AD resolution so it's values can be between 0 and 1024. (of course it can be between 0-255 aswell)
LC recieves these values and divides them by 4 to get values between 0 and 255. Then this data is send back to the arduino
as brightness for the led. This works now.

A couple of important observations. 
If you open for update and you don't read periodicly LC will hang pretty quickly it seems. That was what bit me this morning.
A send in time didn't get executed. I just could figure out what was happening. since the arduino was not sending anything.
You need to empty the buffer even if the arduino isn't sending anything. This is crucial
I guess in that case open for writing might do the trick but if you open for update you NEED to read the buffer regularly!!.

Another habit I developt is disconnecting the arduino after a scatch upload. I pull the USB plug first before establishing contact with LC.
I don't know if it's neccesary and I will dive into this once I got a stable system to see if it matters but I did notice I had fewer
crashes since I do this. So this is just for what it might be worth.

Another thing I noticed when doing the write to driver is: the result will contain eof instead of empy. I don't know what this means but
I noticed if it didn't return eof LC would hang thereafter.

One more strange thing I notice. Sometimes altough the stack was frontmost it's window wouldn't show as focused,
which means the close/maximize etc. buttons would be grayed. Clicking on the titelbar sometimes would help for a
very short period and then go grey again. Often the titelbar would just stay grye what so ever. 

Well the demo is still incomplete and rough so use at own risk. The third card is the interesting one.
The parts that are implemented seem to work reiably now and it's been running for minutes withou a problem
swiching and fidling with the sensors, the LED will nicely change it's brightness. So Yes it looks like we are getting somewhere.
Now I need to implement the sample rate command so I can test how fast I can send and recieve.

Hope this proves usefull, will keep you posted

Happy coding,
   Claudi




More information about the use-livecode mailing list