Arduino + Android USB闹钟

时间:2016-04-27 16:02:13

标签: java android arduino usb

我试图为我的Arduino uno 3发出警报 我为Android和Arduino编写了一个应用程序。

Arduino代码

const int przycisk = 2;    
int buttonState = 0;      
int wtes = 0;

void setup() {
    Serial.begin(9600);  
    pinMode(przycisk, INPUT);
}

void loop() {
  buttonState = digitalRead(przycisk);

  if(buttonState==LOW){ 
     wtes=0;
  }

  if(buttonState==HIGH && wtes == 0) {
     Serial.print("TAK");  
     wtes=1;
  } 
}

Android java

UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() { // Defining a Callback which triggers whenever data is read.
        @Override
        public void onReceivedData(byte[] arg0) {
            String data = null;
            try {
                data = new String(arg0, "UTF-8");
                final CharSequence ftext = data;

                if (ftext.toString().equalsIgnoreCase("TAK")) {
                    String numer = "00000000000"; //
                    String smswiad = "masssage";

                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage(numer, null, smswiad, null, null);
                }
            }
            catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

        }
    };

当我按下按钮时,Arduino会发送" TAK"到智能手机然后Android发送短信。

按下按钮时发送短信,但并非总是如此 为什么这样?

0 个答案:

没有答案