본문 바로가기

Project/Flex Keyboard

20191030

구부림 센서의 값을 받아 구부러졌는지의 여부를 나타내는 코드를 짜 보았다.

int temp[5] ={0,0,0,0,0};
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int sV = analogRead(A0);
  temp[0] = temp[1];
  temp[1] = temp[2];
  temp[2] = temp[3];
  temp[3] = temp[4];
  temp[4] = sV;
  int sum = temp[0]+temp[1]+temp[2]+temp[3]+temp[4];
  Serial.print("sensorValue = "); Serial.print(sV);
  Serial.print(" | checkSum = "); Serial.println(sum>=1000*5?100:-100);
}

5번의 주기를 배열에 저장하여 합이 5000이상이면 참을 출력하여 자유로운 값을 보정해주는 코드를 짰다.

파란색은 원래 구부림 센서의 값, 빨간색은 보정 후 구부러졌는지 여부를 확인할 수 있는 코드이다.

'Project > Flex Keyboard' 카테고리의 다른 글

20191103  (0) 2019.11.03
20191002  (0) 2019.10.02
20180925  (0) 2019.09.26
20180920  (0) 2019.09.20
20190918  (0) 2019.09.18