Arduino for the Agility Mat Prototype

For the Agility Mat prototype, I really wanted to be able to show how it can read user movement, and how the users would be able to play games on it. Thus the below code was born (At bottom of page to make scrolling easier).

The code uses a simple switch statement to create the feel that the player is following a randomised LED around the mat, when really it is a preset routine, and every button can activate it regardless of where it is pressed. This made the overall coding experience easy, and also ensured a fall back, when for example, in our presentation a button failed, I could always press another button with my heel to progress the switch case.

The Code.

This code is used to read what zone of the mat is being activated, and prints it to the serial, allowing for a readable ‘Area Active’ dialogue, that is accompanied with a timestamp.

The Code.
This data will be used by the phone app to create heat maps and track user movements on the mat.
int ledPin1 = 4; //SETUP OF LED PINS
int ledPin2 = 5;
int ledPin3 = 6;
int ledPin4 = 7;
int ledPin5 = 8;

int button1 = 9; //SETUP OF BUTTON PARALLEL CIRCUIT

int state = 0; //SWITCH CASE VARIABLE SETUP
int old = 0;
int buttonPoll = 0;


void setup() {
  // put your setup code here, to run once:
  pinMode (ledPin1, OUTPUT);
  pinMode (ledPin2, OUTPUT);
  pinMode (ledPin3, OUTPUT);
  pinMode (ledPin4, OUTPUT);
  pinMode (ledPin5, OUTPUT);

  pinMode (button1, INPUT);

  digitalWrite(ledPin1, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin3, LOW);
  digitalWrite(ledPin4, LOW);
  digitalWrite(ledPin5, LOW);



  Serial.begin(9600);
}

void loop() {

  buttonPoll = digitalRead(button1);
  if (buttonPoll == HIGH) {
    delay(50);
    buttonPoll = digitalRead(button1);
    if (buttonPoll == LOW) {
      state = old + 1;
    }
  }
  else {
    delay(100);
  }
  switch (state) {
    case 1:
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      old = state;
      break;

    case 2:
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, HIGH);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      old = state;
      break;

    case 3:
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, HIGH);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      old = state;
      break;

    case 4:
      digitalWrite(ledPin1, LOW); `
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, HIGH);
      digitalWrite(ledPin5, LOW);
      old = state;
      break;

    case 5:
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, HIGH);
      old = state;
      break;

    case 7:
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, HIGH);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      old = state;
      break;

    case 8:
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      digitalWrite(ledPin5, LOW);
      old = state;
      break;

    default:
      digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, HIGH);
      digitalWrite(ledPin5, LOW);
      old = 0;
      break;


      //---HEAT MAP DATA SPITTER---//
      //---START---//
      if ( digitalRead(9) == HIGH )
        Serial.println ("Area 1 Active");
      else delay(100)
        ;
      if ( digitalRead(10) == HIGH )
        Serial.println ("Area 2 Active");
      else delay(100)
        ;
      if ( digitalRead(11) == HIGH )
        Serial.println ("Area 3 Active");
      else delay(100)
        ;
      if ( digitalRead(12) == HIGH )
        Serial.println ("Area 4 Active");
      else delay(100)
        ;
      if ( digitalRead(13) == HIGH )
        Serial.println ("Area 5 Active");
      else delay(100)
        ;
      if ( digitalRead(A0) == HIGH )
        Serial.println ("Area 6 Active");
      else delay(100)
        ;
      if ( digitalRead(A1) == HIGH )
        Serial.println ("Area 7 Active");
      else delay(100)
        ;
      if ( digitalRead(A2) == HIGH )
        Serial.println ("Area 8 Active");
      else delay(100);
      //---END OF HEAT MAP DATA SPITTER---//




      //---END OF HEAT MAP DATA SPITTER---//

  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *