Hola
Tengo dudas respecto a unos comandos. Queriendo iniciar un poco en lo relacionado a programación en Arduino, encontré un proyecto que me pareció muy entretenido para comenzar. Consiste en un cronómetro con sensores infrarrojos que permite calcular el tiempo que toma un autito de juguete en dar vuelta a una pista en la que también marca la que toma menos tiempo.
La cosa es que intenté hacer el circuito con el Arduino, con buenos resultados. Pero desde hace poco he querido hacer 2 sensores conectados al mismo circuito para poder medir el tiempo que demora el auto en recorrer una distancia definida, en el cual intentando conectarlo al circuito, me marca uno de los 2, debiendo desconectar los otros para que los primeros
La duda es, ¿es realmente posible poner 2 sensores para lo que busco? (1 que inicia el tiempo y otro que lo termina).
Adjunto la página y los comandos que utilizo.
Comandos:
// Load libraries for LCD display and create and lcd object
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// Initialise variables
int sensorPin = A1;
int ledPin = 13;
int sensorValue = 0;
unsigned int start = 0;
unsigned int lap = 0;
unsigned int tempo = 0;
char last[16];
void setup()
{
// Initialise the LCD display
lcd.begin(16,2);
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Ready");
// Initialise serial communication at 9600 bps
Serial.begin(9600);
// Power up the IR sensor
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
void loop()
{
sensorValue = analogRead(sensorPin);
if (sensorValue > 900) // An object is detected
{
tempo = millis(); // Record the current time
lap = tempo - start; // Calculate the lap time
start = tempo; // Reset the clock
// Calculate the seconds and milliseconds for nicer printout of lap time
unsigned int sec = lap / 1000;
unsigned int msec = lap - sec*1000;
// Print out the lap time on the serial port
sprintf(last, "Last: %02u"%03u", sec, msec);
Serial.println(last);
// Print out the lap time on the LCD display
lcd.setCursor(0, 0); // Set the cursor on the first display line
lcd.print(last);
Serial.println("---");
delay(1000); // Needed to avoid that the car triggers multiple detections
}
}