@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);
 }
Exemplo n.º 2
0
    /**
     * Called repetitively while the IOIO is connected.
     *
     * @throws ConnectionLostException When IOIO connection is lost.
     * @throws InterruptedException When the IOIO thread has been interrupted.
     * @see ioio.lib.util.IOIOLooper#loop()
     */
    @Override
    public void loop() throws ConnectionLostException, InterruptedException {
      int re = r.nextInt(100 - 0); // random number between 0 and 100 for rotation enable
      int ra = r.nextInt(3 - 0); // random number between 0 and 100 for rotation angle

      if (actionEnable) {
        if (re <= 1) { // % chance that the head will rotate
          switch (ra) {
            case 0:
              newPos = 1000;
              break; // limit 600
            case 1:
              newPos = 1550;
              break;
            case 2:
              newPos = 2000;
              break; // limit 2450
            default:
              break;
          }

          if (newPos != currentPos) {
            led_.write(true);
            pwm.setPulseWidth(newPos);
            currentPos = newPos;
            Log.d("ROTATE", "Moving to position: " + newPos + "...");
            Thread.sleep(1000);
            Log.d("ROTATE", "At position: " + newPos);
            initIR();
          }
        } else {
          float measVal = iRSensors.input.read();
          float measVolt = iRSensors.input.getVoltage();
          if (!action.TTSE.t1.isSpeaking()) {
            if (iRSensors.motionDetect(measVal, measVolt)) {
              led_.write(false);
              Log.d(
                  "MOTION",
                  "Detected motion!"
                      + " BaseVal: "
                      + iRSensors.baseValue
                      + "/"
                      + measVal
                      + ", BaseVolt: "
                      + iRSensors.baseVolt
                      + "/"
                      + measVolt);

              action.executeGreeting(); // execute a random greeting

              action.executeRandActivity();
              /*
                                          if(action.getCurrentAction() == ActionEngine.ACTION_PAGE ||
                                                  action.getCurrentAction() == ActionEngine.ACTION_QUIZ){
                                              pageQueue.add(action.getWebPage());
                                              interactionTimer.run();
                                          }
              */
              switch (action.getCurrentAction()) {
                case ActionEngine.ACTION_PAGE:
                  pageQueue.add(action.getWebPage());
                  interactionTimer.run();
                  break;
                case ActionEngine.ACTION_QUIZ:
                  pageQueue.add(action.getQuiz());
                  interactionTimer.run();
                  break;
                default:
                  break;
              }

              /*
              int rn = r.nextInt(2-0);
              if(rn == 1) action.executeQuiz();
              else action.executePage();
              */
              // action.executeMakeTweet("IR sensor voltage: " + measVolt);
              // action.executeTweetSearch(true);
              // action.executeTimelineSearch(true);
              // action.executeRSS(true);

              Log.d("IR SENSORS", "reinitializing...");
              initIR();
            } else {
              led_.write(true);
            }
          } else {
            led_.write(true);
          }
        }
      }

      Thread.sleep(100);
    }