We are submitting it as a zip

What it does

YOU CAN SAIL OR YOU CAN DIE

How we built it

We implemented a series of pushbuttons, LEDs, and a joystick on a breadboard in series with 10k ohm resistors. It drew power from the arduino, we established a voltage source and a ground, and different pins to correspond with the LEDs, pushbuttons, and joystick switch so we have control over them. This was meant to be a joystick for the game.

We used pygame, a python library, to code out the game which was a bit of a challenge. This game can be ran in an IDE that runs python.

Challenges we ran into

We ran into a lot of challenges. We decided to code it out in python because python is a comparatively easier language to work with, but that did not make using it any less difficult. We used the pygame library, which was our first time dealing with this library. So, a lot of the functions for this library we were unfamiliar with which made troubleshooting hard. We kept getting weird indent errors. And animating it was harder than we expected it to be. Little things that you would gloss over when playing a game yourself, aren’t so little to implement. Something as small as the waves moving gave us difficulty, plus we were getting a lot of issues with lagging.

We are a group majoring in Electrical and Computer Engineering, so we didn’t just want to account for the software aspect, but the hardware aspect as well. We wanted to program a joy stick and push buttons via a microcontroller, so we essentially created a controller for the game from scratch, this required understanding the usb protocol and latching the letters onto different buttons and different directions that the joystick go in. This required researching and understanding the advanced aspects of the arduino and modifying the firmware, so it’ll be able to workout side of the arduino code itself. It required a lot of trial and error and theres still more work to be done for the software and the hardware, we can improve our game from a lot of directions and make transitions smoother.

Accomplishments that we're proud of

What we learned

MAKING GAMES ARE HARD. Things always map out better in our heads then in actual implementation, so while things worked out well when initially planning, we ran into errors we didn’t even account for in the actual game itself, but hey we did it!

Code for Microcontroller:

///credit to https://mitchtech.net/arduino-usb-hid-keyboard/ for the help // Define pin numbers const int buttonPin1 = 2; // Button 1 connected to pin 2 const int buttonPin2 = 3; // Button 2 connected to pin 3 const int buttonPin3 = 4; // Button 3 connected to pin 4 const int buttonPin4 = 5; // Button 4 connected to pin 5 const int ledPin1 = 6; // LED 1 connected to pin 6 const int ledPin2 = 7; // LED 2 connected to pin 7 const int ledPin3 = 8; // LED 3 connected to pin 8 const int ledPin4 = 9; // LED 4 connected to pin 9

//defining the VRX and VRY pins

define VRX_PIN A0

define VRY_PIN A1

//https://gist.github.com/MightyPork/6da26e382a7ad91b5496ee55fdc73db2 for hex inputs const int SPACE_KEY = 44; const int ESCAPE_KEY = 9; const int Q_KEY = 20; const int E_KEY = 8; const int W_KEY = 26; const int A_KEY = 4; const int S_KEY = 22; const int D_KEY = 7;

//IDK WHAT THIS DOES uint8_t buf[8] = { 0 };

int xValue = 0; //Stores value of the X axis int yValue = 0; //Stores value of the Y axis

// Variables to store button states int buttonState1 = 0; int buttonState2 = 0; int buttonState3 = 0; int buttonState4 = 0;

void setup() { //For testing purposes Serial.begin(9600);

// Initialize LED pins as outputs pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); // Initialize button pins as inputs pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); pinMode(buttonPin3, INPUT); pinMode(buttonPin4, INPUT);

delay(500); }

void loop() { //Testing for the joystick inputs xValue = analogRead(VRX_PIN); yValue = analogRead(VRY_PIN);

//Joysticks being defined in quadrants attempt 1 // if(xValue>=524) // Serial.println("w"); // if(xValue<524) // Serial.println("S"); // if(yValue>=524) // Serial.println("D"); // if(yValue<524) // Serial.println("A"); // if(xValue<262 && yValue<262){ // Serial.print("a s"); //bottom left // } // if(xValue <= 1023 && xValue >= 786 && yValue < 262){ // Serial.print("w a");//top leftt // } // if(xValue <= 1023 && xValue > 786 && yValue >= 786){ // Serial.print("w d"); //top right // } // if(xValue < 262 && yValue >= 786){ // Serial.print("s d"); //bottom right // } //doesnt work not correct bounds attemp 2 // if (xValue < 262 && yValue < 262) { // Serial.print("a s"); // bottom left // } // if ((xValue >= 786 && xValue <= 1023 && yValue < 262)) { // Serial.print("w a"); // top left // } // if ( (xValue >= 786 && xValue <= 1023 && yValue >= 786)) { // Serial.print("w d"); // top right // } // if (xValue < 262 && yValue >= 786) { // Serial.print("s d"); // bottom right // } // if (xValue > 524 && yValue < 786 && yValue > 262 && yValue < 786) { // Serial.print("w"); // top // } // if (xValue < 262 && yValue >= 262 && yValue < 524) { // Serial.print("a"); // left // } // if (yValue >= 262 && yValue < 786 && xValue < 524) { // Serial.print("s"); // bottom // } // if (xValue > 524 && yValue < 262 && yValue >= 786) { // Serial.print("d"); // right // } //attempt 3 //approach with small dead zone in center int xMax = 1024; //max definitions of the bounds in the joystick ranges int yMax = 1024; // int x = xValue; //redefined for faster coding cuz im lazy // int y = yValue;

//defining the dead zone int deadZoneMax = 786; int deadZoneMin = 262; //top left int topLeftMaxX = 1024; int topLeftMinX = 787; int topLeftMaxY = 262; int topLeftMinY = 0; //bottom left int range = 301; //top right int topRightMaxX = 1024; int topRightMinX = 787; int topRightMaxY = 1024; int topRightMinY = 787; //bottom right int bottomRightMaxX = 301; int bottomRightMinX = 0; int bottomRightMaxY = 1023; int bottomRightMinY = 787; //w key int wxmaxrange = 1023; int wxminrange = 786; int wymaxrange = 786; int wyminrange = 262; //a key int axmaxrange = 786; int axminrange = 262; int aymaxrange = 262; int ayminrange = 0; //s key int sxmaxrange = 786; int sxminrange = 262; int symaxrange = 1024; int syminrange = 786; // //d key // int dxmaxrange = 0; // int dxminrange = 0; // int dymaxrange = 0; // int dyminrange = 0;

// Serial.println(xValue); // Serial.println(yValue); if(deadZoneMin < xValue && xValue < deadZoneMax && deadZoneMin < yValue && yValue < deadZoneMax){ // Serial.print("Dead zone"); //no keys activated }else if(xValue <= range && yValue <= range ){ // Serial.print("bottom Left"); //a and s

buf[2] = S_KEY; Serial.write(buf,8); releaseKey(); buf[2] = A_KEY; Serial.write(buf,8); releaseKey();

}else if(topLeftMinX < xValue && xValue < topLeftMaxX && topLeftMinY <= yValue && yValue < topLeftMaxY){ // Serial.print("top Left"); //hits w and a

buf[2] = A_KEY; Serial.write(buf,8); releaseKey(); buf[2] = W_KEY; Serial.write(buf,8); releaseKey(); }else if(topRightMinX < xValue && xValue < topRightMaxX && topRightMinY <= yValue && yValue < topRightMaxY){ // Serial.print("Top right"); //hits w and d

buf[2] = D_KEY; Serial.write(buf,8); releaseKey(); buf[2] = W_KEY; Serial.write(buf,8); releaseKey(); }else if(bottomRightMinX <= xValue && xValue <= bottomRightMaxX && bottomRightMinY <= yValue && yValue <= bottomRightMaxY){ // Serial.print("Bottom right"); //hits s and d

buf[2] = S_KEY; Serial.write(buf,8); releaseKey(); buf[2] = D_KEY; Serial.write(buf,8); releaseKey(); }else if(wxminrange <= xValue && xValue <= wxmaxrange && wyminrange <= yValue && yValue <= wymaxrange){ // Serial.print("W"); buf[2] = W_KEY; Serial.write(buf,8); releaseKey();

//hits w }else if(axminrange <= xValue && xValue <= axmaxrange && ayminrange <= yValue && yValue <= aymaxrange){ // Serial.print("A"); digitalWrite(ledPin2, HIGH); //hits a buf[2] = A_KEY; Serial.write(buf,8); releaseKey(); }else if(sxminrange <= xValue && xValue <= sxmaxrange && syminrange <= yValue && yValue <= symaxrange){ // Serial.print("d"); //?????IDK????? IT WORKS?????? digitalWrite(ledPin3, HIGH); //hits d buf[2] = D_KEY; Serial.write(buf,8); releaseKey(); }else{ // Serial.print("s"); digitalWrite(ledPin4, HIGH); //hits s buf[2] = S_KEY; Serial.write(buf,8); releaseKey(); }//all the above code is horrible and i apologize, im in ece not comp sci

// Serial.print("/n"); // digitalWrite(ledPin1, LOW); // digitalWrite(ledPin2, LOW); // digitalWrite(ledPin3, LOW); // digitalWrite(ledPin4, LOW);

// delay(3000);

//a // if(xValue ) // delay(3000); // Serial.println("x = "); // Serial.println(xValue); // delay(300); // Serial.println("y = "); // Serial.println(yValue); // delay(400); // delay(2000);

// // Read the state of the buttons buttonState1 = digitalRead(buttonPin1); buttonState2 = digitalRead(buttonPin2); buttonState3 = digitalRead(buttonPin3); buttonState4 = digitalRead(buttonPin4);

// If button 1 is pressed, turn on LED 1 if (buttonState1 == HIGH) { //esc

digitalWrite(ledPin1, HIGH); // Turn on LED 1

} else { digitalWrite(ledPin1, LOW); // Turn off LED 1 buf[2] = SPACE_KEY; Serial.write(buf,8); releaseKey(); }

// If button 2 is pressed, turn on LED 2 if (buttonState2 == HIGH) { //keyboard //entr digitalWrite(ledPin2, HIGH); // Turn on LED 2 } else { buf[2] = ESCAPE_KEY; Serial.write(buf,8); releaseKey(); digitalWrite(ledPin2, LOW); // Turn off LED 2 }

// If button 3 is pressed, turn on LED 3 if (buttonState3 == HIGH) { //q digitalWrite(ledPin3, HIGH); // Turn on LED 3 } else { buf[2] = Q_KEY; Serial.write(buf,8); releaseKey(); digitalWrite(ledPin3, LOW); // Turn off LED 3 }

// If button 4 is pressed, turn on LED 4 if (buttonState4 == HIGH) { //e digitalWrite(ledPin4, HIGH); // Turn on LED 4 } else { buf[2] = E_KEY; Serial.write(buf,8); releaseKey(); digitalWrite(ledPin4, LOW); // Turn off LED 4 } } //this times the output release void releaseKey(){ buf[0] = 0; buf[2] = 0; Serial.write(buf,8); delay(20); }

Built With

Share this project:

Updates