// HackBerry Lab Gaming System
//Zane Cochran
//Janosch Spohner

// LCD Setup *********************************************************************************************************TRNX
#include "SPI.h"          // SPI Library
#include "ILI9341_t3.h"   // ILI9341 Library

#define TFT_DC  9                             // Data Connect Pin
#define TFT_CS 10                             // Chip Select Pin
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);  // Initialize TFT Screen
int screenX = 320; int screenY = 240;         // Set Screen Size Parameters

// Control Setup ****************************************************************************************************
int joystickX = A9;                                 // Joystick X on Analog 1
int joystickY = A8;                                 // Joystick Y on Analog 0
int buttonPins[] = {5, 6, 7, 8};                // A, B, C, D - Button Pin Assignments

int buttonStatus[] = {0, 0, 0, 0, 0, 0};            // X, Y, A, B, C, D   -   Button Status (Pressed/NotPressed)
int lastButtons[] = { -1, -1, -1, -1, -1, -1};      // X, Y, A, B, C, D   -   Previous Button Status (Pressed/NotPressed)
unsigned long buttonTimers[] = {0, 0, 0, 0, 0, 0};  // X, Y, A, B, C, D   -   Button Timers

// Speaker Setup ****************************************************************************************************
int speaker = 20;                             // Speaker Attached to Digital 20

// Main Prog Variables **********************************************************************************************
int state = 0;                                // Which State to Start In
boolean debug = false;                        // Toggle Debug Values (for Serial Printing)

void setup() {
  Serial.begin(9600);                         // Serial Printing (for Debugging)

  tft.begin();                                // Begin Screen
  tft.setRotation(3);                         // Set Rotation to 90 degrees
  tft.fillScreen(ILI9341_BLACK);              // Clear the Screen
  randomSeed(analogRead(A4));
  for (int i = 0; i < 4; i++) {
    pinMode(buttonPins[i], INPUT);            // Set Buttons to Input
  }
}

void loop() {
  switch (state) {
    case 0: runSplash(); break;                  // Splash Screen
    case 1: runMain(); break;                    // Main Menu
    case 2: runController(); break;              // Controller Debugging
    case 3: runAbout(); break;                   // About Screen
    case 4: runLunar(); break;                   // Lunar Game
    case 5: runBerryRacer(); break;               // Berry Racer Game
  }

  //frameRate();  // Show current framerate
}
