Diody

Diody

Program: który po zeskanowaniu karty magnetycznej zapala diody na mikrokontrolerze w odpowiednim miejscu.

Jak w opisie.

Kompilator: Eclipse

Galeria:

Program w akcji.

Kod programu:

Diody – backend:

package com.friendlyarm.LEDDemo;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import com.friendlyarm.AndroidSDK.HardwareControler;

public class LEDTestingActivity extends Activity implements OnClickListener {
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
    	Button btdioda = (Button)findViewById(R.id.btdioda);
    	Button btczysc = (Button)findViewById(R.id.btczysc);
    	final EditText etId = (EditText)findViewById(R.id.eTid);
    	btczysc.setOnClickListener(new OnClickListener() {	
			@Override
			public void onClick(View v) {
				etId.setText("");	
				HardwareControler.setLedState(0,0);
				HardwareControler.setLedState(1,0);
				HardwareControler.setLedState(2,0);
				HardwareControler.setLedState(3,0);
			}
		});
    	btdioda.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {	
			if (etId.getText().toString().equals("0010869779"))
			{		
				HardwareControler.setLedState(0,1);
				HardwareControler.setLedState(1,0);
				HardwareControler.setLedState(2,0);
				HardwareControler.setLedState(3,0);
			}
			else if (etId.getText().toString().equals("0010880775"))
			{
				HardwareControler.setLedState(0,0);
				HardwareControler.setLedState(1,0);
				HardwareControler.setLedState(2,1);
				HardwareControler.setLedState(3,0);
				
			}
			else if (etId.getText().toString().equals("0010875393"))
			{
				HardwareControler.setLedState(0,0);
				HardwareControler.setLedState(1,0);
				HardwareControler.setLedState(2,0);
				HardwareControler.setLedState(3,1);
			}
			else if (etId.getText().toString().equals("0010868757"))
			{
				HardwareControler.setLedState(0,0);
				HardwareControler.setLedState(1,1);
				HardwareControler.setLedState(2,0);
				HardwareControler.setLedState(3,0);
			}
			else if (etId.getText().toString().equals("0010868757"))
			{
				HardwareControler.setLedState(0,0);
				HardwareControler.setLedState(1,1);
				HardwareControler.setLedState(2,0);
				HardwareControler.setLedState(3,0);
			}
			}
		});
    }
	@Override
	public void onClick(View v) {}	
}

Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <EditText
        android:id="@+id/eTid"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/id" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btdioda"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/dioda" />

    <Button
        android:id="@+id/btczysc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/wyczysc" />

</LinearLayout>