25 Mayıs 2015 Pazartesi

AppInventor ile IOIO LDR Analog Voltaj Okuma :

AppInventor ile IOIO LDR Analog Voltaj Okuma :

Devre :

Ekran Tasarımı :




Blok Diyagram :


Çıktı :

Ön Bilgi için örnek : App Inventor ile IOIO kullanımı

11 Mayıs 2015 Pazartesi

IOIO LDR Analog Voltaj Okuma

IOIO LDR Analog Voltaj Okuma :

AndroidManifest.xml :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />
MainActivity.java :
public class MainActivity extends IOIOActivity {
    ToggleButton button_;
    TextView tv_;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button_ = (ToggleButton) findViewById(R.id.toggleButton);
        tv_ = (TextView) findViewById(R.id.textView2);
    }
    class Looper extends BaseIOIOLooper {
        private DigitalOutput led_;
        private AnalogInput a_in;
        @Override        
        protected void setup() throws ConnectionLostException {
            led_ = ioio_.openDigitalOutput(0, true);
            a_in = ioio_.openAnalogInput(40);
        }
        @Override        
        public void loop() throws ConnectionLostException, InterruptedException {
            led_.write(!button_.isChecked());
            runOnUiThread(new Runnable() {
                @Override                public void run() {
                    try {
                        tv_.setText(String.format("%f", a_in.getVoltage()));
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    } catch (ConnectionLostException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    }
    protected IOIOLooper createIOIOLooper() {
        return new Looper();
    }
}