標題:
Arduino
[打印本頁]
作者:
ray
時間:
2018-10-3 16:52
標題:
Arduino
#include<SoftwareSerial.h>
SoftwareSerial BT(8,9);
const int xpin = A0;
const int ypin = A1;
const int zpin = A2;
const int pin = 4;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(xpin,INPUT);
pinMode(ypin,INPUT);
pinMode(zpin,INPUT);
pinMode(pin,OUTPUT);
BT.begin(38400);
}
void loop() {
// put your main code here, to run repeatedly:
int x = analogRead(xpin);
x=((float)x-331.5)/65*9.8;
Serial.print("x=");
Serial.println(x);
int y = analogRead(ypin);
y=((float)y-331.5)/65*9.8;
Serial.print("y=");
Serial.println(y);
int z = analogRead(zpin);
z=((float)z-331.5)/65*9.8;
Serial.print("z=");
Serial.println(z);
if(x > 5)
{
digitalWrite(pin,1);
BT.available();
BT.write("1");
}
else
{
digitalWrite(pin,0);
BT.available();
BT.write("0");
}
delay(100);
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2