How do i get the stamp to read an external input like a text file?
sgthos
Posts: 5
I'm trying to program the stamp to move a servo based on a changing input (video pixels). How do i get the stamp to read values from a text file?
Comments
Just in case my approoach is the one for you here is some of my code. It is just an extract, so I have not shown the variable declarations.
By the way, do you really mean a text file? How are you getting the data from the camera to the Stamp? Do you have a PC accessing the webcam, then feeding the raw stream to the Stamp? If so, it would be much better to have the PC do the initial image processing. Even if you're having the PC store the raw data on something like a memory stick, it's still better to have the PC do some initial image processing and pass on more limited data to the Stamp.
Post Edited (Mike Green) : 3/26/2008 3:14:08 AM GMT
Having said that, you CAN write a PC-based program to recieve 'directions' over the serial port from the BS2, and the PC-based program can open the file and send the bytes to the BS2 over the serial link. From your posts it sounds like you already KNOW how to write code on the PC to open a text file and read individual values, so it sounds like you need to know how to write a program on the BS2 that will accept bytes over the serial link, and use those bytes to command servo positions.
That can be as simple as:
ServoPos1 VAR WORD
ServoPos2 VAR WORD
ServoPin1 PIN 1
ServoPin2 PIN 2
MAIN:
SERIN 16, 16864, 20, Timeout, [noparse][[/noparse]DEC ServoPos1, DEC ServoPos2]
Timeout:
IF ServoPos1 = 0 THEN
ServoPos1 = 750
ENDIF
IF ServoPos2 = 0 THEN
ServoPos2 = 750
ENDIF
PULSOUT ServoPin1, ServoPos1
PULSOUT ServoPin2, ServoPos2
GOTO MAIN