Hi.
This is my first venture into Arduino so I'm a total n00b although I have messed with simple electronics many years ago. I'm trying to create a simple ultrasound sensor to drive computer-based installation. I got an Uno and a XL MaxSonar EZ1 MB1210 sensor and set it up as directed. It works! My code is below (adapted from Bruce Allen's original code):
//Digital pin 7 for reading in the pulse width from the MaxSonar device.
//This variable is a constant because the pin will not change throughout execution of this code.
const int pwPin = 7;
//variables needed to store values
long pulse, cm;
void setup() {
//This opens up a serial connection to shoot the results back to the PC console
Serial.begin(9600);
//Set up the input pin.
pinMode(pwPin, INPUT);
}
void loop() {
//Used to read in the pulse that is being sent by the MaxSonar device.
//Pulse Width representation with a scale factor of 58uS per centimetre.
pulse = pulseIn(pwPin, HIGH);
//58uS per cm
cm = pulse/58;
Serial.println(cm);
delay(10);
}
I'm reading it from Adobe Director 11.5 using the Serial Xtra. The set up code is below:
on setUpSensor
if objectP(gXtra) then
gXtra.closePort()
gXtra = VOID
end if
put new(xtra "SerialXtra","foo@whatever.com","XXXXXXXXXX",90) into gXtra
if objectP(gXtra) then
gxtra.OpenPort("COM3") -- arduino
gXtra.setProtocol(9600, "n", 8, 1)
end if
end
The problem is that
I have to press the reset button on the Arduino every time I run the Director code. It seems that as I am setting up comms to the board in this code it stops the Arduino board from running the sensor program on board. Anyone any ideas why? Sorry if this is simple - I couldn't find anything on this particular issue.
Thanks, Paul.