is that possible to setup one pin as a input and output

in arduino uno is that possible to setup, one pin as a output and input sametime.
example void setup() {

pinMode(p1,INPUT);
pinMode(p1,OUTPUT);

}

I don't think there is anyway to do this. Even if there was, that way is probably incorrect.

How could a pin possibly be both? If you're writing to it then you know the state and if you're reading from it then writing to it would make it impossible to read. Maybe if you explain why you think you need to do that someone could recommend a way to do what you want.

ganesh07: in arduino uno is that possible to setup, one pin as a output and input sametime. example void setup() {

pinMode(p1,INPUT); pinMode(p1,OUTPUT);

}

Only the last instruction will remain in effect, however both will execute. First, the compiler will link in the "input" code and then the compiler will link in the "output" code. When run, p1 will be an input for an instant and will flip over to an output pin ... Staying in output mode until changed.

You may find this discussion about four-value logic enlightening: http://en.wikipedia.org/wiki/Four-valued_logic

Ray

ganesh07:
in arduino uno is that possible to setup, one pin as a output and input sametime.
example void setup() {

pinMode(p1,INPUT);
pinMode(p1,OUTPUT);

}

Not like that, but there are ways to light an LED that reflects the input to a pin if that is what you want to do.

ganesh07: in arduino uno is that possible to setup, one pin as a output and input sametime. example void setup() {

pinMode(p1,INPUT); pinMode(p1,OUTPUT);

}

Not at the SAME TIME. But you can switch back and forth between input and output as often as you like.

This is commonly done when sending and receiving serial data that goes on only one pin, for example:

    while (bits--) {
        digitalWrite (_SCK, LOW);
        pinMode (_DATA, OUTPUT);
        digitalWrite (_DATA, data & _BV (bits) ? HIGH : LOW);
        digitalWrite (_SCK, HIGH);
        pinMode (_DATA, INPUT_PULLUP);
        digitalRead (_DATA) ? data |= _BV (bits) : data &= ~_BV (bits);
    }

thanks guys. im doing a project for my school culminating, so i m tring to make a piezo sensor as a Knock Sensor and speaker

Well you can switch to an input to detect a knock and then change it over to an output to make a sound.