Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* pinouts:
- * A0: analog y axis
- * A1: analog x axis
- * A2: ADC5
- * A3: ADC4
- * A4: ADC1
- * A5: ADC0
- * 9: R1
- * 10: R2
- * 11: L2
- */
- #include "HID-Project.h"
- #define NUM_BUTTONS 14
- #define BTN_UP 0
- #define BTN_DOWN 1
- #define BTN_LEFT 2
- #define BTN_RIGHT 3
- #define BTN_A 4
- #define BTN_START 5
- #define BTN_Y 6
- #define BTN_L1 A1
- #define BTN_X 8
- #define BTN_R1 A0
- //#define BTN_R1 9
- //#define BTN_R2 10
- //#define BTN_L2 11
- #define BTN_B 12
- #define BTN_SELECT 13
- const int battPin = A2;
- const int chargingPin = A3;
- const int chargedPin = A4;
- //const int shutdownPin = A5;
- const int redPin = 9;
- const int greenPin = 10;
- const int bluePin = 11;
- const float lowBattVoltage = 0; //FIX
- const float shutdownVoltage = 0; //FIX
- float voltage;
- int charging;
- int charged;
- void setup() {
- for (int i = 0; i < NUM_BUTTONS; i++) {
- pinMode(i, INPUT_PULLUP);
- }
- pinMode(A0, INPUT_PULLUP);
- pinMode(A1, INPUT_PULLUP);
- pinMode(battPin, INPUT);
- pinMode(chargingPin, INPUT);
- pinMode(chargedPin, INPUT);
- // pinMode(shutdownPin, OUTPUT);
- pinMode(redPin, OUTPUT);
- pinMode(greenPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
- Serial.begin(9600);
- // Sends a clean report to the host. This is important on any Arduino type.
- Gamepad.begin();
- Keyboard.begin();
- }
- void loop() {
- //Battery monitor
- /* voltage = analogRead(battPin) * (5.00 / 1023.00);
- Serial.println(voltage);
- charging = digitalRead(chargingPin);
- charged = digitalRead(chargedPin);
- if (voltage <= shutdownVoltage) && (charging == LOW) {
- Keyboard.press(KEY_LEFT_CTRL);
- Keyboard.press(KEY_ESC);
- delay(100);
- Keyboard.releaseAll();
- }
- if (charged == HIGH) {
- Serial.println("charged");
- analogWrite(redPin, 255);
- analogWrite(greenPin, 255);
- analogWrite(bluePin, 245);
- } else if (charging == LOW) {
- Serial.println("charging");
- analogWrite(redPin, 220);
- analogWrite(greenPin, 218);
- analogWrite(bluePin, 248);
- } else if (voltage <= lowBattVoltage) {
- Serial.println("lowbatt");
- analogWrite(redPin, 245);
- analogWrite(greenPin, 255);
- analogWrite(bluePin, 255);
- } else {
- Serial.println("power");
- analogWrite(redPin, 255);
- analogWrite(greenPin, 245);
- analogWrite(bluePin, 255);
- }
- */
- //Gamepad
- bool down = !digitalRead(BTN_DOWN);
- bool up = !digitalRead(BTN_UP);
- bool left = !digitalRead(BTN_LEFT);
- bool right = !digitalRead(BTN_RIGHT);
- Gamepad.dPad1(GAMEPAD_DPAD_CENTERED);
- if (down) {
- Gamepad.dPad1(GAMEPAD_DPAD_DOWN);
- if (left) {
- Gamepad.dPad1(GAMEPAD_DPAD_DOWN_LEFT);
- } if (right) {
- Gamepad.dPad1(GAMEPAD_DPAD_DOWN_RIGHT);
- }
- } else if (up) {
- Gamepad.dPad1(GAMEPAD_DPAD_UP);
- if (left) {
- Gamepad.dPad1(GAMEPAD_DPAD_UP_LEFT);
- } if (right) {
- Gamepad.dPad1(GAMEPAD_DPAD_UP_RIGHT);
- }
- } else if (left) {
- Gamepad.dPad1(GAMEPAD_DPAD_LEFT);
- } else if (right) {
- Gamepad.dPad1(GAMEPAD_DPAD_RIGHT);
- }
- for (int i = BTN_A; i < NUM_BUTTONS; i++) {
- if (!digitalRead(i)) {
- Gamepad.press(i);
- } else {
- Gamepad.release(i);
- }
- }
- if (!digitalRead(A0)) {
- Gamepad.press(A0);
- } else {
- Gamepad.release(A0);
- }
- if (!digitalRead(A1)) {
- Gamepad.press(A1);
- } else {
- Gamepad.release(A1);
- }
- Gamepad.write();
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement