Whats-A-One?
Jump to navigation
Jump to search
This is a look at the Electrical Reality of Arduino Digital Inputs. (Under Construction 11/1/14)
The Software Sketch is below.
An example of the sketch output is
Arduino Digital Inputs: What's A ONE Anyway??
This is a look at the Electrical Reality of Arduino Digital Inputs. (Under Construction 11/1/14)
The Software Sketch is below.
An example of the sketch output is
[/file/view/ArduinoInputPinBehavior.txt/529092518/ArduinoInputPinBehavior.txt ArduinoInputPinBehavior.txt]
[/file/view/ArduinoInputPinBehavior.txt/529092518/ArduinoInputPinBehavior.txt ArduinoInputPinBehavior.txt]
- [/file/detail/ArduinoInputPinBehavior.txt Details]
- [/file/view/ArduinoInputPinBehavior.txt/529092518/ArduinoInputPinBehavior.txt Download]
- 12 KB
Software Sketch: Cut and Paste into Arduino IDE
/* YourDuinoStarter Examples: ? What's A ONE Anyway ? - Reads input as Digital and Analog, displays output on Serial Monitor as: - Analog Input as Integer - Analog Input as Floating Point - Digital Input (Boolean) - Pin 13 LED (following Digital Boolean value) - CONNECTIONS: - FIRST Try: Input pin to floating wire - SECOND Try: ADD 10K Potentiometer as Voltage Divider: - +5 to Ground. - Wiper to both Digital Input Pin and to Analog input - THIRD Try: ADD 10K Resistor and 1000uF capacitor from Pot to inputs for slow changes. - V1.02 11/01/15 - SEE the comments after "//" on each line below Questions: terry@yourduino.com */ /*-----( Declare Constants and Pin Numbers )-----*/ #define INPUT_PIN 3 // Pins to connect to #define ANALOG_PIN A0 #define PIN_13_LED 13 // The onboard LED /*-----( Declare Variables )-----*/ int digitalValue; // Holds 1 or 0 read as digital input int analogIntValue; // Holds the integer 10 bit value read in float analogVoltsValue; // Int Value converted to 0..5V Floating Point //---------------------------------------------------------------------- void setup() /****** SETUP: RUNS ONCE ******/ { pinMode (PIN_13_LED,OUTPUT) ; // PIN 13 is an OUTPUT pinMode (INPUT_PIN, INPUT) ; // PIN 2 is an INPUT (Not really needed) Serial.begin(9600); //Start sending to "Serial Monitor" Serial.println(); // Make a new line Serial.println("YourDuino Starter: Show Input Pin Behavior."); delay(1000); }//--(end setup )--- //---------------------------------------------------------------------- void loop() /****** LOOP: RUNS CONSTANTLY ******/ { Serial.println(); // Make a new line /*---( Read and display the 10 bit integer value )------*/ analogIntValue = analogRead(ANALOG_PIN); //Read value Serial.print("Analog:10 Bit Integer(0..1023) = "); Serial.print(analogIntValue,DEC); // Print value /*---( Convert and display the 0.0 to 5.0V value )------*/ analogVoltsValue = analogIntValue * (5.0 / 1024.0); Serial.print(" Analog:0.0 to 5.0V = "); Serial.print(analogVoltsValue, 2); // Print value /*---( Read and display the Digital (Boolean) value )------*/ Serial.print(" Boolean Value = "); digitalValue = digitalRead(INPUT_PIN); Serial.print(digitalValue, 1); // Print value if (digitalValue == HIGH) { digitalWrite(PIN_13_LED, HIGH) ; // LED ON } else { digitalWrite(PIN_13_LED, LOW) ; // LED OFF } delay(500); // Switch may be "bouncing". Wait just a bit }//--(end main loop )---