2018年12月27日 星期四

WEEK15

Arduino+雙軸搖桿

void setup() {
  // put your setup code here, to run once:
  pinMode(2,INPUT);
  digitalWrite(2,HIGH);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int val = analogRead(A0);
  int x=val/8;
  if(x<2)x=2;
  Serial.write(x);
  if(digitalRead(2)==HIGH)Serial.write(0);
  else Serial.write(1);
  delay(100);///100 millis seconds
}



























沒有留言:

張貼留言