Using the WIRE command - ozarchie/BlueBasic GitHub Wiki
WIRE P<0-2>(<variable>) | OUTPUT | INPUT | LOW | HIGH | READ <variable> | READ ADC <variable> | TIMEOUT <microseconds> | WAIT LOW <variable> | WAIT HIGH <variable> | WAIT <microseconds> | PULSE <variable> | END
WIRE is a protocol for connecting certain peripheral devices such as the DHT11 or DHT22. BlueBasic WIRE command allows reading sequential data from a pin by specifying a start sequence, typically used in simple one-wire interfaces, and then issuing read, readadc, or readmultiple sequences. The default count is set by the size of the variable/array used.
It does NOT allow writing data serially to the pin, so ONEWIRE devices are not supported.
| Parameter | Function |
|---|---|
| P | Select the pin e.g. P0(0) |
| OUTPUT | Set pin to OUTPUT mode |
| INPUT | Set pin to INPUT mode |
| LOW | Set the pin LOW |
| HIGH | Set the pin HIGH |
| READ | Read a single byte |
| READ ADC | Read the ADC |
| TIMEOUT | Set the READ/ADC/PULSE timing |
| WAIT LOW | Wait until the wire goes low, maximum set by TIMEOUT |
| WAIT HIGH | Wait until the wire goes high, maximum set by TIMEOUT |
| WAIT | Wait for microseconds |
| PULSE | Read bits into byte array variable |
1010 DIM B(83)
1015 PINMODE P1(4) INPUT PULLUP
1020 WIRE P1(4) OUTPUT, HIGH, LOW, WAIT 1000, INPUT, PULSE B, OUTPUT HIGH, END
This line outputs a 1000us start pulse to the device attached to P1_4, and then reads back the sequence of bits from the device into the array B.
The number of reads is determined by the size of the PULSE .
B can then be reassembled into the returned value.