Go Down

Topic: Can´t control more than one digital output (Read 265 times) previous topic - next topic

SisterParadise

Hi everyone, I´m trying to make an h bridge controlable by the serial monitor and just turns for one way and I can stop it with the program below. When I try to set the other way turning I haven´t a high output which comands the other way, and it don´t works. What can I try to do?

Wawa

OP's code
Code: [Select]
char a = 0;
void setup()
{
  Serial.begin(2000000);
  pinMode(8, OUTPUT);
  pinMode(12, OUTPUT);
}
void loop() {
  if (Serial.available() > 0)
  {
    a = Serial.read();
    Serial.print(a);
    Serial.print("\n");

    if (a == 'e')
      digitalWrite(12, HIGH);

    if (a == 'a')
      digitalWrite(8, HIGH);
    digitalWrite(12, LOW);


    if (a == 's')
      digitalWrite(8, LOW);
    digitalWrite(12, LOW);

  }
}

If() statements with more than one line need curly braces.
Leo..

Silente

After you can put things like this: firstly switch the high pin LOW, and after seitch the low pin HIGH.
But haven't you a way to switch the motor (or whatever into the H bridge) completly off?) witchout turn of piwer?
Dove va un numero va una variabile o una funzione. E dove va una boolean va un insieme di test.

Se vuoi ottenere devi saper spiegare

In pichi capiscono l'importanza di formattare, sii tra di essi

Grumpy_Mike

Code: [Select]
Serial.begin(2000000);
I don't think an Arduino can go that fast.

Wawa

It's the highest baud rate on the serial monitor, and works fine here.
Leo..

Go Up