One more question. When I connect to the IOIO board with this code both lines of text show the same numbers and do not return to 0 when the wire is unhooked from the pin. Also numbers continue to display for probably 10 times the amount of time the pin was connected.
Please see the video. The pin was just plugged in for a second. (only one pin). Anyone see what I am missing? http://youtu.be/IyI-T3F1pYw <http://youtu.be/30kqDhbOQYw> Thanks for the help with the code. I think its starting to come together. class PulseInputThread extends Thread { private final PulseInput input_; private final Timer timer_; public PulseInputThread(PulseInput input,Timer timer) { input_ = input; timer_ = timer; } private synchronized void read() throws ConnectionLostException { TimerTask task = new TimerTask() {public void run() { interrupt(); }}; timer_.schedule(task, 1000); try { last_ = 1/input_.waitPulseGetDuration(); task.cancel(); } catch (InterruptedException e) { last_ = 0; } } public void run() { try { while (true) { read(); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (ConnectionLostException e) { e.printStackTrace(); } } public synchronized float getLastReading() { return last_; } } class Looper extends BaseIOIOLooper { PulseInputThread thread1_; PulseInputThread thread2_; @Override protected void setup() throws ConnectionLostException { PulseInput input1_ = ioio_.openPulseInput(new DigitalInput.Spec(1), ClockRate.RATE_62KHz, PulseMode.POSITIVE, false); PulseInput input2_ = ioio_.openPulseInput(new DigitalInput.Spec(3), ClockRate.RATE_62KHz, PulseMode.POSITIVE, false); Timer t = new Timer(); thread1_ = new PulseInputThread(input1_, t); thread2_ = new PulseInputThread(input2_, t); thread1_.start(); thread2_.start(); } @Override public void loop() throws ConnectionLostException { setText1(thread1_.getLastReading()); setText2(thread2_.getLastReading()); try { Thread.sleep(1000); } catch (InterruptedException e) { } } public void disconnected() { try { thread1_.join(); thread2_.join(); } catch (InterruptedException e) { } } } @Override protected IOIOLooper createIOIOLooper() { return new Looper(); } private void setText1(final float freqHZ1) { runOnUiThread(new Runnable() { @Override public void run() { row1.setText("Seeds per second: " + freqHZ1); } }); } private void setText2( final float freqHZ2) { runOnUiThread(new Runnable() { @Override public void run() { row2.setText("Seeds per second: " + freqHZ2); } }); } -- You received this message because you are subscribed to the Google Groups "ioio-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/ioio-users. For more options, visit https://groups.google.com/d/optout.
