' call and response serial example for picBasic Pro. ' This example waits for a byte on the incoming serial connection, ' and checks to see that the byte equals 65. ' It then sends the values of three sensors on pins RA0 - RA2. ' this example uses two arrays to hold the ADC values, ' and the byte values that they're converted to for sending. ' serial RX is on pin RC7 ' serial TX is on pin RC6 ' constant to set the baud rate: inv9600 con 16468 ' define variables: adcVar var word(3) byteVar var byte(3) channel var byte inByte as byte main: ' read sensors, convert to bytes: for channel = 0 to 2 adcin channel, adcVar(channel) byteVar(channel) = adcVar(channel) / 4 next ' read serial data in: serin2 portc.7, inv9600, [inByte] ' if you got the message from director, send out data: if inByte = 65 then serout2 portc.6, inv9600, [byteVar(0), byteVar(1), byteVar(2)] end if end sub