Skip to content

Commit c89ac1e

Browse files
committed
IOIO: added working analogInput example
- CPU usage seems excessive, requires profiling on the java side
1 parent 969eda4 commit c89ac1e

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

ioio/samples/slider-pot.bas

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import ioio
2+
3+
analogIn = ioio.openAnalogInput(46)
4+
5+
print "wait for connect"
6+
ioio.waitForConnect()
7+
print "ready!!!"
8+
9+
while 1
10+
print analogIn.read()
11+
delay 100
12+
wend
13+
14+
print "done"
15+
16+
17+

ioio/src/main/java/net/sourceforge/smallbasic/ioio/IOService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
public class IOService implements IOIOLooperProvider {
1414
private static final String TAG = "IOService";
15-
private static final int MAX_PINS = 43;
15+
private static final int MAX_PINS = 46;
1616
private static IOService instance = null;
1717

1818
private final ConnectionController connectionController;
@@ -24,7 +24,7 @@ private IOService() {
2424
connectionController = new ConnectionController(this);
2525
looper = new IOServiceLooper();
2626
ioTasks = new ArrayList<>();
27-
usedPins = new Boolean[MAX_PINS];
27+
usedPins = new Boolean[MAX_PINS + 1];
2828
}
2929

3030
public static IOService getInstance() {
@@ -57,7 +57,7 @@ public void start() {
5757

5858
private void registerPin(int pin) throws IOException {
5959
if (pin != -1) {
60-
if (pin < 0 || pin >= MAX_PINS) {
60+
if (pin < 0 || pin > MAX_PINS) {
6161
throw new IOException("invalid pin: " + pin);
6262
}
6363
if (usedPins[pin] != null && usedPins[pin]) {
@@ -88,6 +88,7 @@ public void incompatible(IOIO ioio) {
8888

8989
@Override
9090
public void loop() throws ConnectionLostException, InterruptedException {
91+
Thread.sleep(100);
9192
for (IOTask next: ioTasks) {
9293
next.loop();
9394
}

0 commit comments

Comments
 (0)