Is it possible to use the digital OUTs as INs? [SOLVED]

Hello ALL,

How is it possible to use the pins named "DIGITAL" as digital INs?

Final answers: 1. http://arduino.cc/forum/index.php/topic,125731.msg946047.html#msg946047 2. http://arduino.cc/forum/index.php/topic,125731.msg946400.html#msg946400

If you are asking if they could be used as inputs and outputs, then yes all you have to do is say if it is an input or output in the void setup, here is more http://arduino.cc/en/Reference/Setup

As jonathanped said, they can be used for either input or output. You have to call the pinMode function

So to make digital pin 10 an input pinMode(10, INPUT);

To set it for output pinMode(10, OUTPUT);

One thing to add though is that it doesn't have to happen in the setup function but almost always that is where you want to set it. It can be set anywhere at anytime and you can even change the mode in the same program. This is rare however and the only time I can think when one does this is with the PING sensor which requires you to send and receive a signal on the same pin.

Hope that doesn't add to the confusion. :)

Ok, how do I print "0" or "1" if the button on pin 53 is pressed and the other number if not.

MDTech-us_MAN: Ok, how do I print "0" or "1" if the button on pin 53 is pressed and the other number if not.

Have you looked at any of the examples that come with the Arduino software?

Have you tried a felt / marker type pen?

"Ok, how do I print "0" or "1" if the button on pin 53"

pin 53? if (digitalRead(53)==true) { Serial.println("Pin 53 is true"); //sort of, is it printlin or writeln, i can never remember unless front of the IDE. }

it IS println I'm currently testing that...

if (digitalRead(53)==true)
 {
    Serial.println("Pin 53 is true");
 //sort of, is it printlin or writeln, i can never remember unless front of the IDE.
}

The digitalRead() function returns HIGH or LOW, not true or false. If you are going to do an explicit compare, as you should, then use the right thing on the other side of the equality operator.

MDTech-us_MAN: Hello ALL,

How is it possible to use the pins named "DIGITAL" as digital INs?

First choose the programming language you want to use for building an interface (GUI). Second you set the I/O as either "high" or "low" to receive and send data, so if you wanted to use I/O Number 9 to turn a servo motor either right or left you can do it pretty easily.

Here is some VB.NET 2010 code for the computer side, AKA your GUI.

All you need are two buttons...

Imports System.IO Imports System.IO.Ports Imports System.Threading

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With SerialPort1 SerialPort1.Close() SerialPort1.PortName = "com4" 'change com port to match your Arduino port SerialPort1.BaudRate = 9600 SerialPort1.DataBits = 8 SerialPort1.Parity = Parity.None SerialPort1.StopBits = StopBits.One SerialPort1.Handshake = Handshake.None SerialPort1.Encoding = System.Text.Encoding.Default 'very important!

End With

End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

SerialPort1.Open() SerialPort1.Write("3") SerialPort1.Close() End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click SerialPort1.Open() SerialPort1.Write("4") SerialPort1.Close() End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End End Sub

As you can see the "SerialPort1.Write("4")" and "SerialPort1.Write("3")" under each button are the commands being sent to the Arduino threw USB in the form of a packet. As you can imagine the sketch has the number 3 and 4 defined as I/O 9 and each one moves the motor 180 degrees from each other.

Hope this helps,

Rob http://whatisacnc.com

imrobc:

MDTech-us_MAN: Hello ALL,

How is it possible to use the pins named "DIGITAL" as digital INs?

First choose the programming language you want to use for building an interface (GUI). ... Here is some VB.NET 2010 code for the computer side, AKA your GUI.

What on earth does this have to do with the original poster's question?

[quote author=James C4S link=topic=125731.msg945878#msg945878 date=1349456138]

imrobc:

MDTech-us_MAN: Hello ALL,

How is it possible to use the pins named "DIGITAL" as digital INs?

First choose the programming language you want to use for building an interface (GUI). ... Here is some VB.NET 2010 code for the computer side, AKA your GUI.

What on earth does this have to do with the original poster's question? [/quote]

How does it not relate to the posters question? I am saying yes you can "use the pins named "DIGITAL" as digital INs" At least this is my take on it, maybe I am wrong? Whats the problem?

imrobc: How does it not relate to the posters question? I am saying yes you can "use the pins named "DIGITAL" as digital INs" At least this is my take on it, maybe I am wrong? Whats the problem?

The original poster was asking if an Arduino sketch that can perform digital reads on the digital pins. You stated you need a GUI front end and then proceeded to give him a Visual Basic program that talks over the serial port (and you left out the corresponding sketch to boot).

Discussing a GUI front end in VB it is about as far away from "is it possible to use the pins named "DIGITAL" as digital INs" as one can get.

Not trying to be a jerk about it but your post is a bit off topic.

imrobc:

[quote author=James C4S link=topic=125731.msg945878#msg945878 date=1349456138]

imrobc:

MDTech-us_MAN:
Hello ALL,

How is it possible to use the pins named “DIGITAL” as digital INs?

First choose the programming language you want to use for building an interface (GUI).

Here is some VB.NET 2010 code for the computer side, AKA your GUI.

What on earth does this have to do with the original poster’s question?

How does it not relate to the posters question?
I am saying yes you can “use the pins named “DIGITAL” as digital INs”
At least this is my take on it, maybe I am wrong?
Whats the problem?
[/quote]

YES, Thanks for the VB code! (I would need it later any way), but, I need the → ARDUINO ← code now.

I need to accurately print the current state of the button (1 if pressed, 0 if not). If I use:

Serial.println(digitalRead(53));

I get a VERY in accurate result (takes time to switch from 0 to 1 (first a couple 1s here and there then more and more and finally everything is 1)).
Is the a better way?!

Setup code:

Serial.begin(9600);
pinMode(53, INPUT);

Maxwell D.

EDIT: Now I get ALL 0s:

0
0
0
0
...
0
0
0

Entire code:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(53, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly: 
  Serial.println(digitalRead(53));
}

How is the switch on pin 53 connected. You're not using the built-in pull ups; what else have you got on that pin?

internal pullups:

  Serial.begin(9600);
  pinMode(53, INPUT);// assumes switch closure connects pin to Gnd
digitalWrite (53, HIGH);  


// IDE 1.0.1 also supports:
pinMode(53, INPUT_PULLUP); // seperate digitalWrite not needed

Answer 1:

CrossRoads: internal pullups:

  Serial.begin(9600);
  pinMode(53, INPUT);// assumes switch closure connects pin to Gnd
digitalWrite (53, HIGH);  

// IDE 1.0.1 also supports: pinMode(53, INPUT_PULLUP); // seperate digitalWrite not needed

EXACTLY! that is what I needed!!! I needed the digitalWrite part! The INPUT_PULLUP does not work on pins 22-53 on the Arduino Mega.

My aim is to make a miniature keyboard. (I will need 38 buttons for that :) :P )

Where can I get A LOT of cheap miniature buttons?

"The INPUT_PULLUP does not work on pins 22-53 on the Arduino Mega."

Really! Have to tuck that one away.

CrossRoads: "The INPUT_PULLUP does not work on pins 22-53 on the Arduino Mega."

Really! Have to tuck that one away.

Well I would like to see a reference source for that before tucking it away?

Lefty

Thanks for the help!

No now, I have 1 more question, where can I get 38+ miniature buttons? :P

MDTech-us_MAN: Thanks for the help!

No now, I have 1 more question, where can I get 38+ miniature buttons? :P

At a elves tailor shop?