The original design for my game controller was made with the intention of using four separate PIR motion sensors in conjunction with the Circuit Playground Express. However, during the construction of the controller, I realized there were hardware inconsistencies and thus that idea was shelved. This final design uses only two of the PIR motion sensors in addition to a potentiometer. The conceptual model was designed to resemble the arrows of Friday Night Funkin. I used a thermoplastic called Worbla in order to create a sturdy shape for the arrows. These were created before discovering the hardware issues but I decided to use three of the arrows in the end. The signifiers of this design were the arrows allowing the user to easily identify which direction the sensor would correspond to. The feedback is that the user can see the corresponding arrows pressed on-screen while the relevant motion is applied to the sensors and potentiometer. The input and output mapping are as follows: The potentiometer, when turned counterclockwise, will output a left arrow or the “A” key. When turned clockwise the output will be the right arrow or the “D” key. The two motion sensors will output the up and down arrows or the “W” and “S” keys respectively. The affordances are the four input mechanics the user has access to. All other components are hidden.
Do you think this design is too confusing given the use of containers meant for the previously intended hardware?
#include <Keyboard.h>
#include <Adafruit_CircuitPlayground.h>
#include <Adafruit_Circuit_Playground.h>
int pirState = LOW;
int pirState2 = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int val2 = 0;
boolean rightPressed = false;
boolean leftPressed = false;
int potenNum = 0;
int potenMap = 0;
void setup() {
pinMode(3, INPUT);
pinMode(2, INPUT);
Serial.begin(9600);
Keyboard.begin();
}
void loop(){
val = digitalRead(3); // read input value
val2 = digitalRead(2); // read input value
potenNum = analogRead(A1);
//Serial.print(potenNum);
// The position of the potentiometer is mapped to a value to determine left or right
potenMap = map(potenNum, 0, 1023, 0, 10);
// Press Left Arrow
if(potenMap == 10){
//Serial.println(potenMap);
Keyboard.press(216);
leftPressed = true;
}
// Press Right Arrow
if(potenMap == 0){
//Serial.println(potenMap);
Keyboard.press(215);
rightPressed = true;
}
// Release Right Arrow
if(potenMap != 0 && rightPressed == true){
Keyboard.release(215);
rightPressed = false;
}
// Release left arrow
if(potenMap != 10 && leftPressed == true){
Keyboard.release(216);
leftPressed = false;
}
// check if the input is HIGH (MOTION!!!)
if (val == HIGH) {
// Press Up Arrow
if (pirState == LOW) {
// we have just turned on the up key
Keyboard.press(218);
Serial.println("Motion 1 detected!");
pirState = HIGH;
}
} else if ((val == LOW)) {
if (pirState == HIGH){
// we have just turned off the up key
Keyboard.release(218);
Serial.println("Motion 1 ended!");
pirState = LOW;
}
}
// check if the input is HIGH (MOTION!!!)
if (val2 == HIGH) {
// Press Down Arrow
if (pirState2 == LOW) {
// we have just turned on the down key
Keyboard.press(217);
Serial.println("Motion 2 detected!");
pirState2 = HIGH;
}
} else if ((val2 == LOW)) {
if (pirState2 == HIGH){
// we have just turned off the down key
Keyboard.release(217);
Serial.println("Motion 2 ended!");
pirState2 = LOW;
}
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.