I
I
iilinegor2013-12-19 12:33:42
Arduino
iilinegor, 2013-12-19 12:33:42

Assigning values ​​to pins in arduino

The problem is that 2 parts of the code separately work correctly, and together the values ​​of 10 and 13 pins are taken from the last assignment.

#include <Bounce.h>
Bounce right_Pin = Bounce( 11,5 ); 
Bounce left_Pin = Bounce( 12,5 ); 

int right;
int left;

void setup() {
  pinMode(10, OUTPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
  pinMode(13, OUTPUT);
  Serial.begin(9600); 
}

void loop() {
  right_Pin.update ( );
  left_Pin.update ( );

  right = right_Pin.read();
  left = left_Pin.read();

  digitalWrite(10, HIGH);
  digitalWrite(13, LOW);

  if (right == HIGH ) {
    Serial.print("RIGHT!\n" );
  }

  if (left == HIGH) {
    Serial.print("LEFT!\n" );
  }

  digitalWrite(13, HIGH);
  digitalWrite(10, LOW);
  delay(30);

  if (left == HIGH && right == HIGH)
  {
    Serial.print("DOUBLE!\n" );
  }
delay(100);
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
iilinegor, 2013-12-19
@iilinegor

Found a solution: make it through analog outputs

#include <Bounce.h>
Bounce right_Pin = Bounce( 11,5 ); 
Bounce left_Pin = Bounce( 12,5 ); 

int right;
int left;

void setup() {
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  Serial.begin(9600); 
}

void loop() {

  right_Pin.update ( );
  left_Pin.update ( );

  right = right_Pin.read();
  left = left_Pin.read();

  delay(100);

  if (analogRead(A0) > 900 || analogRead(A1) > 900) {
    Serial.print("RIGHT!\n" );
    digitalWrite(10, HIGH);
    tone(11, 300, 200);
  }

  delay(100);
  digitalWrite(10, LOW);

  if (analogRead(A0) > 600 && analogRead(A0) < 700 &&
    analogRead(A1) > 600 && analogRead(A1) < 700) {
    Serial.print("DOUBLE!\n" );
    digitalWrite(9, HIGH);
  }
}

A
Alexander, 2013-12-19
@Papagatto

And left and right are reset every time?

Y
Yegor S, 2013-12-19
@gorbln

Your question is not entirely clear.
What are the 2 parts? What does it mean to work correctly?
What would you like to get and what is not possible?
If something does not work as intended, you can correct this as a preventive measure:
to this:
Otherwise, I don’t remember what the priority of operations in arduino is.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question