Kristof
Published © CC0

Footpad game controller

In order to achieve more indoor physical exercise while there is a threat of SARS-COV-2 outdoors, I worked on this simple game controller.

BeginnerShowcase (no instructions)6 hours2,267
Footpad game controller

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SparkFun piezo element
×1
Resistor 1M ohm
Resistor 1M ohm
×1
plywood ±40 cm X ±40 cm X ±1 cm
×2
Aluminium L profile ±2 cm X ±2 cm X ±0.6 m
×1
Accessory, Screw
Accessory, Screw
×33
Jumper wires (generic)
Jumper wires (generic)
×1
Hardware, Washer
Hardware, Washer
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Code

Testing Software for Floor Pad Game Controller

C/C++
This is a very simple allows for testing the hardware in the Arduino serial monitor
/*
 * By Eye4Tech.info
 * Released under Creative Common Zero License
 * This code reads 4 analog signals from Piezo Electric Crystal elements and convert the signal into pressed yes=no.
 * Although set as a game controler for future use we made a small running game in which steps made in a set time are counted
 * Debug set to 1 prints additional information to the serial monitor is used to write the programme
 * Logic set to 1 gives the values of four sensors
 * Game  set to 1 counts the steps in a set time.
 */

// Treshold levels with higher up and lower down treshold "schmitt-trigger" approach
#define ThresholdUp  500           // value becomes high if reading becommes equal or higher than this value
#define ThresholdLow  50           // value becomes low  if reading becommes lower than this value

// Code inclusion excludion settings
#define Debug          0           // to test the code
#define Logic          0           // to have the logic printed out, best when not the running game counter
#define Game           1           // running game

// constant values 
const uint8_t PIEZO_0  =    A0;    // piezo output left
const uint8_t PIEZO_1  =    A1;    // piezo output back
const uint8_t PIEZO_2  =    A2;    // piezo output right
const uint8_t PIEZO_3  =    A3;    // piezo output front
bool Reading[4]    = {0,0,0,0};
bool OldReading[4] = {0,0,0,0};
bool change        =         0;
uint16_t EndTime   =         0;    // time to end of exercise
uint16_t ExerTime  =         0;    // duration of exercise in microseconds
int  StepCounter   =         0;

void setup() 
{
  Serial.begin(9600);
  // When game is set above this will ask for the time the person wants to race
  #if Game
    { 
      Serial.print  ("Give a one digit number of minutes you want to exercise: ");
      while (!ExerTime)
      {
        if (Serial.available() > 0)
        {
          char Minutes = Serial.read();
          if (isDigit(Minutes))
          { 
            Serial.print  (Minutes);
            ExerTime = 60000*(int(Minutes )-48);    // 1 is ASCII 49
            Serial.print  ("\nYour chosen exercise time is ");
            Serial.print  ( Minutes        );
            Serial.print  (" minutes or "  );
            Serial.print  ( ExerTime       );
            Serial.println(" microseconds.");
            Serial.println("We are ready to record your race ;-)");
          }
        }
      }
    }
  #endif
}

void loop() 
{
  // read Piezo ADC values
  int piezoADC0 = analogRead(PIEZO_0);
  int piezoADC1 = analogRead(PIEZO_1);
  int piezoADC2 = analogRead(PIEZO_2);
  int piezoADC3 = analogRead(PIEZO_3);
  
  // Use a schmitt trigger approach with higher up and lower down treshold to set yes no values.
  if (piezoADC0 >= ThresholdUp  & !Reading[0]) Reading[0] =1;
  if (piezoADC0 <  ThresholdLow &  Reading[0]) Reading[0] =0;
  if (piezoADC1 >= ThresholdUp  & !Reading[1]) Reading[1] =1;
  if (piezoADC1 <  ThresholdLow &  Reading[1]) Reading[1] =0;
  if (piezoADC2 >= ThresholdUp  & !Reading[2]) Reading[2] =1;
  if (piezoADC2 <  ThresholdLow &  Reading[2]) Reading[2] =0;
  if (piezoADC3 >= ThresholdUp  & !Reading[3]) Reading[3] =1;
  if (piezoADC3 <  ThresholdLow &  Reading[3]) Reading[3] =0;


  // verify if the reading changed the array values
  if (Logic)
  {
    change = 0;                      // assume no change at the start
    for (int i=0; i < 4; i++)
    {
      if (Reading[i] != OldReading[i])
      {
        change = 1;                  // indicate a change in values
        #if Debug
        {
          Serial.println("The values have been changed");
        }
        #endif
        break;                       // if one value is changed no other check is required
      }
    }
   
  }
  
  // if the value changed and Logic is on print the logic values
  if (change && Logic) 
  {
    Serial.print  (Reading[0]    );
    Serial.print  (",  "         );
    Serial.print  (Reading[1]    );
    Serial.print  (",  "         );
    Serial.print  (Reading[2]    );
    Serial.print  (",  "         );
    Serial.print  (Reading[3]    );
    Serial.print  (", || "       );
    Serial.print  (OldReading[0] );
    Serial.print  (",  "         );
    Serial.print  (OldReading[1] );
    Serial.print  (",  "         );
    Serial.print  (OldReading[2] );
    Serial.print  (",  "         );
    Serial.print  (OldReading[3] );
    Serial.println(""            );
    memcpy(OldReading, Reading, 4);
  }
  if (!change && Debug)
  {
    Serial.println("The values have been NOT been changed");
  }

  // step counter as a simple application for the pad
  if (Game)
  {
    // determine the start of the execise on the left foot when no step was set yet
    if (!EndTime && !StepCounter && Reading[0])
    {
      EndTime = millis() + ExerTime;
      Serial.print  ("Start running!\n");
      /*
      Serial.print  ("Now = "  );
      Serial.print  (millis()  );
      Serial.print  ("\tEnd = ");
      Serial.println(EndTime   );
      */
      OldReading[0]=1;
    }

    // as long as the end time of the exercise is not reached count steps
    // one step is a press left, press right. Counter count on the right step. 
    if (millis() < ExerTime)
    {
      if( OldReading[0] && !Reading[0] && Reading[2] )
      {
        /*
         * L[0] | R[2] | OL[0] | OR[2]
         * 0    | 0    | 0     | 0
         * 1    | 0    | 1     | 0     Conditions         => Set values
         * 0    | 1    | 0     | 1     OL_1 && L_0 && R_1 => OL_0 & OR_1
         * 1    | 0    |               OR_1 && L_1 && R_0 => OL_1 & OR_0
         */
        OldReading[0]= 0 ;
        OldReading[2]= 1 ;
        StepCounter += 1 ;
        Serial.println(StepCounter);
        
      }
      if( OldReading[2] && Reading[0] && !Reading[2] )
      {
        OldReading[0]= 1 ;
        OldReading[2]= 0 ;
      }
    }
    else
    {
      Serial.println("\nYou did it !"    ) ;
      Serial.print  ("You have done "    ) ;
      Serial.print  ( StepCounter        ) ;
      Serial.println(" steps. Well done!") ;
      Serial.print  ("You had around "   ) ;
      Serial.print  (StepCounter/(ExerTime/60000));
      Serial.println(" steps per minute!"          ) ;
      
      while (true)
      {
        // do nothing in a continious look to stop the program
      } 
    }
  }
}

Credits

Kristof

Kristof

2 projects • 3 followers
Sit at home and wash my hands these days.

Comments