Last active
July 19, 2019 00:36
-
-
Save codycodes/e32dac208ad7be80b5bfcbbdf2e0af6d to your computer and use it in GitHub Desktop.
USB switch hacking!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int relayPin = 5; // red | |
int usbDetectPin = 6; // green | |
int button = 7; // purple -> blue/white | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(relayPin, INPUT); | |
pinMode(usbDetectPin, INPUT); // | |
// pinMode(button, OUTPUT); // TODO: we may want this button to be an input | |
// if we want to read its data for debugging | |
pinMode(button, INPUT) // ? attempt to read when the button is pressed, | |
// but may need to update circuit to read this value | |
Serial.begin(9600); | |
} | |
void loop() { | |
// digital read in on pin 2 for input if it's high then toggle | |
int relay = digitalRead(relayPin); | |
int usbDetect = digitalRead(usbDetectPin); | |
// if ( (relay && !usbDetect ) || (!relay && usbDetect) ) { | |
// pressButton(); | |
// } | |
// Serial.println("RELAY: " + (String)relay + " USB: " + (String)usbDetect); | |
int buttonPressed = digitalRead(button); | |
// ! First we will test the value of the LED to see if when we press the button we can read LED's state | |
// ! If successful, we'll then see if we can read when the button is pressed | |
// ! Third -> we can test if we're able to toggle the button via GPIO, which would require changing pinMode to digitalWrite | |
serial.println('LED: ' + (String)usbDetectPin + 'BUTTON PRESSED:' + (String)buttonPressed) //remove this line when changing pinmode | |
// TODO: bridge grounds of arduino and board; make the mosfet circuitry, bridge inactive USB port to fool circuitry | |
} | |
void pressButton(){ | |
Serial.println("Button pressed!"); | |
digitalWrite(button, HIGH); | |
delay(100); | |
digitalWrite(button, LOW); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment