Skip to content

Instantly share code, notes, and snippets.

@codycodes
Last active July 19, 2019 00:36
Show Gist options
  • Save codycodes/e32dac208ad7be80b5bfcbbdf2e0af6d to your computer and use it in GitHub Desktop.
Save codycodes/e32dac208ad7be80b5bfcbbdf2e0af6d to your computer and use it in GitHub Desktop.
USB switch hacking!
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