011345687:
i tried to directly wire up from arduino to RS-232 ( yea seriously). and I try to write a program.i tested this program and i watched the status from the serial monitor, it kept print the value 2FF000D repeatedly
while i send 1 to the monitor, it changed the value to 2FF400D but still repeatedly
and i tried to send another num to monitor, it stopped.how come the value keep looping, how can i send hex once only?
however i tried the above step after i connected between TX,RX and GND of arduino board and 232port 2,3,5 pin.
i sent 1 out , i could see the monitor that showed the hex of 2FF400D, but the remote dimmer didnt turn on.
what's the problem here?
Reference the serial.available() function: http://www.arduino.cc/en/Serial/Available .
Serial.available() returns the number of data bytes available. In your code the statement
if (Serial.available () == 0)
means that every time there are 0 bytes available to read,
Serial.print ( dimmerOFF,HEX);
will be executed.
What you want to do is test for when Serial.available() > 0 and then read the byte from serial. You can then have an if statement, or switch statement to determine what should happen when a given byte is received.