17 April 2022

Project: Tetris Game Controller

 The controller that I chose to make my controller is for an old-time favorite game called Tetris. I chose this game because of not just its simplicity of actively stacking blocks to earn a point as a way to see how interesting it would be to move and rotate the blocks by just using dials. Playing the game this way made it more engaging for the player to play the game. Allowing them to think about what kind of placement they want the blocks to be placed. The controller connects to the pc through USB. The left knob controls the position of the blocks. If you turn it clockwise, it would move the blocks right while if you turn it counterclockwise, it would move the blocks left. The right knob rotates the blocks in their current position. If you slightly flick the box, you can instantly release the block at the position it is currently at.

Questions: There is a mechanic in the game where you can hold on to the current block and swaps them out if the player chooses. What I would like to ask is what would be a good control input for that function.




//Programmer:Joseph Gallup

#include <SimpleRotary.h>

#include <Keyboard.h>

#include <Adafruit_CircuitPlayground.h>


// Pin A, Pin B, Button Pin

SimpleRotary rotary(9,10,0);//RRotary PinA = A2, PinB = A3

SimpleRotary rotary1(2,0,0);//LRotary PinA = A5, PinB = A6

float value;

 

void setup() {

  Serial.begin(9600);

  

  Keyboard.begin();

}


void loop() {

  

  byte i;

  byte b;


  // 0 = not turning, 2 = CW, 3 = CCW

  i = rotary.rotate(); //i = rotate value

  b = rotary1.rotate();//b = rotate value


  if ( i == 1 ) {// Rotate Clockwise inputs A

    Serial.println("CW");

    Keyboard.write('A');

  }


  if ( i == 2 ) {//Rotate CounterClockwise inputs D

    Serial.println("CCW");

    Keyboard.write('D');

  }

  if (b == 1){//Rotate Clockwise inputs W

    Serial.println("BW");

    Keyboard.write('W');

  }

  if (b == 2){//Rotate CounterClockwise inputs S

    Serial.println("BCW");

    Keyboard.write('S');

  }

  value = CircuitPlayground.mic.soundPressureLevel(50);// value equals the microphone input with sound level of 50

  if(value >= 90.00 && value <=100.00  ){// if the value is between 90 and 100 inputs the space bar.

    Keyboard.write(' ');

  }

  Serial.print("Sound Sensor SPL: ");

  Serial.println(value);

}




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.