You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

65 lines
2.1 KiB

/*
* Computer Switchboard
*
* Because interfacing with computers should be fun
* and a keyboard is not enough.
*
* Let's turn a computer into an airplane (interface wise).
*
*/
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 9;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
// I was somewhat confused about this. I thought maybe it would be an output
// to ground, through the resistor, and it would only conduct when grounded, but
// using the input pullup works. I'm not sure if you can detect when an output grounds or is conducting...
pinMode(pushButton, INPUT_PULLUP);
//https://stackoverflow.com/questions/6160963/how-can-i-digitalread-a-pin-that-is-in-pinmode-output
//https://forum.arduino.cc/index.php?topic=183977.0
//This approach doesn't work as you can't read a floating pin reliably
//so don't do it. It always reads zero, or will read noise.
//pinMode(pushButton, OUTPUT);
//digitalWrite(3,HIGH);
//interestingly, you could use a shunt resistor... but more complex
//https://arduino.stackexchange.com/questions/14647/how-can-i-detect-a-disconnected-pin
delay(100);
}
// the loop routine runs over and over again forever:
void loop() {
// easy way
// read the input pin:
// int buttonState = digitalRead(pushButton);
// print out the state of the button:
// Serial.println(buttonState);
delay(10); // delay in between reads for stability
int resultb = 0;
resultb = PINB;
Serial.println(resultb,BIN); //noisy, but reads 0 when low.
// Serial.println(bitRead(PORTB,1));// PORTB is for high or low
// PIN is for reading input. PORTB doesn't work here.
// https://arduino.stackexchange.com/questions/14647/how-can-i-detect-a-disconnected-pin
// not sure what that link is on about, regarding port usage.
delay(100);
}