@Override
 public void loop()
     throws ConnectionLostException,
         InterruptedException { // Loop is a listening function (analogous to an interrupt)
   setNumber(input_.getVoltage()); // Void is a self contained process with no output
   pwmOutput_.setPulseWidth(500000 + 100000 * seekBar_.getProgress());
   led_.write(
       (input_.getVoltage() < 2.5)
           && (toggleButton2_
               .isChecked())); // Turn LED on when pin 40 AND pin 41 are less than 2.5V
   Thread.sleep(10);
 }
Пример #2
0
    @Override
    public void loop() throws ConnectionLostException {
      try {

        float raw = mTempInput.read();

        float R = 10000 / raw - 10000; // R1 = (R2*Vi/Vo) - R2; Voltage Divider

        float steinhart;
        steinhart = R / Ro; // (R/Ro)
        steinhart = (float) Math.log(steinhart); // ln(R/Ro)
        steinhart /= B; // 1/B * ln(R/Ro)
        steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/ To)
        steinhart = (float) (1.0 / steinhart); // Invert
        steinhart -= 273.15; // convert to Cº | celsius = kelvin - 273.15

        String tempString = String.format("%.2f", steinhart) + "ºC";

        setText(tempString);

        Thread.sleep(1000);

      } catch (InterruptedException e) {
        ioio_.disconnect();
        setText(e.getMessage());
      } catch (ConnectionLostException e) {
        setText(e.getMessage());
        throw e;
      }
    }
Пример #3
0
  /**
   * Build the analog input
   *
   * @param ioio handle to the ioio interface
   * @param pin index number of the analog input pin
   * @throws ConnectionLostException when connection to the robot is lost
   */
  public AnalogValueReader(IOIO ioio, int pin) throws ConnectionLostException {
    super(ioio);

    analogInput_ = IOIO_.openAnalogInput(pin);
    analogInput_.setBuffer(8); // we don't need a large buffer, 8 samples is more that enough
    observer_ = null;
    lastValue_ = Float.NaN;
    observerWantsPeriodicNotifications_ = false;
    risingEdgeDetector_ = null;
    fallingEdgeDetector_ = null;
    readerThread_ = null;
  }