My project for the final game controller is about Tapper. The basis of my model is to be inspired by a beer keg. I created this controller because it simulates getting beer into a cup to make you feel like a bartender. The lever is like a nozzle, when pulled down it acts as the space bar which pours the beer in the game. The ultrasonic range sensor is on the left of the controller. Its purpose is to make the player go left when their hand is a certain distance away and stay put when their hand is close to the sensor. On the right, there is the potentiometer that controls the up and down movements, when it's turned to the right the player goes right, and when it turns to the left the player goes down. I wanted the controller to make the player feel immersed in the game. To me, Tapper was a game that was supposed to make you stressed so I didn't want to make the controller feel like it made it more difficult, instead I wanted the controls to feel almost natural so anyone can play it without thinking too hard about it. My question is, is this design a good design does it make sense when you look at it and are there any improvements that could have made it more interesting?
Schemactics
Code
#include<Keyboard.h>
#include<KeyboardLayout.h>
#include<Keyboard_da_DK.h>
#include<Keyboard_de_DE.h>
#include<Keyboard_es_ES.h>
#include<Keyboard_fr_FR.h>
#include<Keyboard_it_IT.h>
#include<Keyboard_sv_SE.h>
#include<Adafruit_CircuitPlayground.h>
#include<Adafruit_Circuit_Playground.h>
#definetrigpin9
#defineechoPin6
#defineled13
// Define a threshold for potentiometer value change
constint hysteresis = 45;
// Variable to store the previous potentiometer value
int previousValue = 0;
voidsetup(){
// put your setup code here, to run once:
CircuitPlayground.begin();
Keyboard.begin();
Serial.begin(9600);
pinMode(trigpin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
}
voidloop(){
// put your main code here, to run repeatedly:
//Accelometer
float x = CircuitPlayground.motionX();
if(x < 1){
Keyboard.press(' ');
Serial.print(x);
Serial.println(" Accelometer");
delay(300);
}else{
Keyboard.release(' ');
}
Serial.print(x);
Serial.println(" Accelometer");
//ultrasonic range sensor:
long duration, distance;
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigpin, HIGH);
delayMicroseconds(10);
digitalWrite(trigpin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
if(distance < 10){
digitalWrite(led, HIGH);
}else{
digitalWrite(led, LOW);
}
if(distance >= 400 || distance <= 0){
Serial.println("Out of range");
}else{
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
if(distance <= 11){
Keyboard.press(KEY_RIGHT_ARROW);
}else{
Keyboard.write(KEY_LEFT_ARROW);
}
//Add loop for Potientometer
// Read the current potentiometer value
int potValue = analogRead(A5); // Adjust the pin as needed
// Check for a significant change in potentiometer value
if(abs(potValue - previousValue) > hysteresis){
if(potValue > previousValue){
// Code for increasing value
Keyboard.write(KEY_UP_ARROW); // Simulate pressing the up arrow key
delay(300);
Keyboard.release(KEY_UP_ARROW); // Release the up arrow key
Serial.println("Potentiometer position increased.");
}elseif(potValue < previousValue){
// Code for decreasing value
Keyboard.write(KEY_DOWN_ARROW); // Simulate pressing the down arrow key
delay(300);
Keyboard.release(KEY_DOWN_ARROW); // Release the down arrow key
Serial.println("Potentiometer position decreased.");
}
// Update the previous value for the next loop iteration
previousValue = potValue;
Serial.print("Pre ");
Serial.println(previousValue);
}else{
Serial.println("Potentiometer position unchanged.");
}
// Print the current potentiometer value
Serial.print("Pot ");
Serial.println(potValue);
}
Video
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.