user35294: So what exactly I am trying to do is control a motor and be able to turn it both ways without any extra parts.
So if the hmp was on (the plus pole) and the hmm (the minus pole) acted like ground the motor should start turning right.
But if the hmp acted in this case as ground and the hmm like the plus pole it should start turning the other way.
I know that it's probably not going to work. I'm just experimenting.
int Hmp=12; // the plus pole
int Hmm=11; // the minus pole

while (HR=0 || Sr > Sl+300) { 
  pinMode(Hmp, OUTPUT);
  digitalWrite(Hmp, HIGH);
  pinMode(Hmm, INPUT);
}

while (HR=1 || Sl > Sr+300) {
  pinMode(Hmp, INPUT);
  pinMode(Hmm, OUTPUT);
  digitalWrite(Hmm, HIGH); 
}


user7508: I just tried what you suggest, and it works fine, with only one (big)
caveat: you can only power this way very low power motors. I did this to
drive the linear motor that moves an HDD head assembly. This motor works
perfectly fine with less than 18 mA.
Note that I switch the Arduino pins between the HIGH and LOW states,
not going through INPUT. Setting the pin to INPUT would send the
motor's inductive kickback through the pin's protection diodes. On the
other hand, the inductance of this motor is presumably tiny...
For anything that can draw more than 40 mA, I would use an
H-bridge. For something between 20 and 40 mA, I may take the
risk of driving it directly if it's for an experiment where I am not
too much concerned about the risk of loosing my Arduino.

user-1: You have to put both pin in OUTPUT mode. You digitalWrite() the "positive" pin HIGH and the "negative" pin LOW.
But, it's not a good idea in this case:

Motor's power requirement exceeds digital output pin current of 40 mA.
Back EMF. Every time you stop the motor, there is a brief current pulse back to your pins. Bad.

The proper ways to control a motor is this:

This will control only one direction. For changing directions, you need a H-Bridge. An H bridge is an electronic circuit that can drive the motor in both directions. 

user35300: I don't think that's going to work.
You'll be better off using a cheap module like the Pololu Pololu DRV8838 which implements a MOSFET H-bridge.
(Note: I'm not related in any way with Pololu.)

user30002: No, it's not going to work - even worse, you risk frying your Arduino -, for the following reasons:

The Arduino data pins can't source (neither sink) enough current for that to work.
The inductive kickback of the motor could fry Arduino pins.

The right way to do what you want to do is using an H-bridge controlled by your Arduino data pins. There are lots of Motor Driver PCB modules for Arduino (most of them based on the inefficient L298 driver IC, which you should ignore and look instead on those based on the TB6612FNG driver IC or similar, because it would be a far better solution) that implement this function.

35294: <p>So what exactly I am trying to do is control a motor and be able to turn it both ways without any extra parts.</p>

<p>So if the hmp was on (the plus pole) and the hmm (the minus pole) acted like ground the motor should start turning right.</p>

<p>But if the hmp acted in this case as ground and the hmm like the plus pole it should start turning the other way.</p>

<p>I know that it's probably not going to work. I'm just experimenting.</p>

<pre><code>int Hmp=12; // the plus pole
int Hmm=11; // the minus pole

while (HR=0 || Sr &gt; Sl+300) { 
  pinMode(Hmp, OUTPUT);
  digitalWrite(Hmp, HIGH);
  pinMode(Hmm, INPUT);
}

while (HR=1 || Sl &gt; Sr+300) {
  pinMode(Hmp, INPUT);
  pinMode(Hmm, OUTPUT);
  digitalWrite(Hmm, HIGH); 
}
</code></pre>
 7508: <p>I just tried what you suggest, and it works fine, with only one (big)
caveat: you can only power this way very low power motors. I did this to
drive the linear motor that moves an HDD head assembly. This motor works
perfectly fine with less than 18&nbsp;mA.</p>

<p>Note that I switch the Arduino pins between the <code>HIGH</code> and <code>LOW</code> states,
not going through <code>INPUT</code>. Setting the pin to <code>INPUT</code> would send the
motor's inductive kickback through the pin's protection diodes. On the
other hand, the inductance of this motor is presumably tiny...</p>

<p>For anything that can draw more than 40&nbsp;mA, I would use an
H-bridge. For something between 20&nbsp;and 40&nbsp;mA, I may take the
risk of driving it directly <em>if</em> it's for an experiment where I am not
too much concerned about the risk of loosing my Arduino.</p>
 -1: <p>You have to put both pin in OUTPUT mode. You digitalWrite() the "positive" pin HIGH and the "negative" pin LOW.</p>

<p>But, it's not a good idea in this case:</p>

<ol>
<li>Motor's power requirement exceeds digital output pin current of 40 mA.</li>
<li>Back EMF. Every time you stop the motor, there is a brief current pulse back to your pins. Bad.</li>
</ol>

<p>The proper ways to control a motor is this:</p>

<p><a href="https://i.stack.imgur.com/hGOCC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hGOCC.jpg" alt="Arduino controlled motor"></a></p>

<p>This will control only one direction. For changing directions, you need a H-Bridge. An H bridge is an electronic circuit that can drive the motor in both directions. </p>
 35300: <p>I don't think that's going to work.</p>

<p>You'll be better off using a cheap module like the Pololu <a href="https://www.pololu.com/product/2990" rel="nofollow noreferrer">Pololu DRV8838</a> which implements a MOSFET H-bridge.</p>

<p>(Note: I'm not related in any way with Pololu.)</p>
 30002: <p>No, it's not going to work - even worse, you risk frying your Arduino -, for the following reasons:</p>

<ol>
<li><p>The Arduino data pins can't source (neither sink) enough current for that to work.</p></li>
<li><p>The inductive kickback of the motor could fry Arduino pins.</p></li>
</ol>

<p>The right way to do what you want to do is <strong>using an H-bridge controlled by your Arduino data pins</strong>. There are lots of Motor Driver PCB modules for Arduino (most of them based on the inefficient L298 driver IC, which you should ignore and look instead on those based on the TB6612FNG driver IC or similar, because it would be a far better solution) that implement this function.</p>
