Gym battle

ModuModus 전시 2007. 11. 9. 14:55
사용자 삽입 이미지


작업 이미지
사용자 삽입 이미지

9V 전지가 달려있는 각각의 미니 아두이노 보드는 2개의 틸트 센서에서 신호를 받아 그 신호를 다른 쪽의 Xbee 아두이노 보드에 보내게 된다.

각각의 device에서 송신하는 코드는 다음과 같다.

--준비중

사용자 삽입 이미지

사용자 삽입 이미지

사용자 삽입 이미지

Stereo에서 수신하는 mp3플레이 코드 입니다.
 


#define HOOLA  3
#define ROPE   1
#define DUMBBEL 2

int incomingByte = 0; // for incoming serial data
int hoolaCount = 0;
int ropeCount = 0;
int dumbbelCount = 0;
int totalCount = 0;
int winningCounters = 0;
int winningLoop = 0;
int val = 0;
int oldWinner = 0;
int winner = 0;
int i = 0;

void restartCounters() {
  hoolaCount = 0;
  ropeCount = 0;
  dumbbelCount = 0;
  totalCount = 0;
}

void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  restartCounters();
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) {
    // read the incoming byte:
    incomingByte = Serial.read();
    totalCount++;
    switch(incomingByte){
    case '3':
      hoolaCount = hoolaCount + 1;
      break;
      // break is optional
    case '1':
      ropeCount = ropeCount + 1;
      break;

    case '2':
      dumbbelCount = dumbbelCount + 1;
      break;
    }
  }

  if (totalCount >=20) {
    if(hoolaCount >= ropeCount && hoolaCount >= dumbbelCount){
      winner = HOOLA;
    }
    else if(ropeCount >= hoolaCount && ropeCount >= dumbbelCount){
      winner = ROPE;
    }
    else if(dumbbelCount >= ropeCount && dumbbelCount >= hoolaCount){
      winner = DUMBBEL;
    }

   if(oldWinner != winner || winningCounters > 40){
      switch (winner) {
      case HOOLA:
        Serial.print("VPF");
        Serial.print(32, BYTE);
        Serial.print("3.mp3");
        break;
      case ROPE:
        Serial.print("VPF");
        Serial.print(32, BYTE);
        Serial.print("1.mp3");
        break;
      case DUMBBEL:
        Serial.print ("VPF");
        Serial.print(32, BYTE);
        Serial.print("2.mp3");
        break;
      default:
        Serial.print("VST");
      }
      Serial.print(13, BYTE);
     winningCounters = 0;
      Serial.flush();
      delay(5000);
    }
    delay(1000);
    restartCounters();
    winningCounters++;
  }
}
: