Hello, I have a code (speed gate) that someone from this forum made for me for my project. It works perfect. Now instead of having it display on the serial monitor, I am hoping to have it display on a 16,2 LCD.
I cant even get a LCD tutorial code to work at the same time as the Speed gate code.
Below is the code for my speed gate. Can anyone help me?
#define LEDon LOW
#define LEDoff HIGH
#define noSIGNAL HIGH
#define SIGNAL LOW
const byte TX = 3;
const byte statusLED = 13;
const byte RX = 2;
byte lastSensorStatus;
float Cardlength=42.6;
//timing stuff
unsigned long checkInputsMillis;
unsigned long detectedMillis;
//************************************************************************************
void setup()
{
Serial.begin(9600);
pinMode(statusLED, OUTPUT);
digitalWrite(statusLED, LEDoff);
pinMode(TX, OUTPUT);
pinMode(RX, INPUT);
tone(TX, 38000);
} //END of setup()
//************************************************************************************
void loop()
{
//********************************************
//time to check the inputs (every 1ms) ?
if (millis() - checkInputsMillis >= 1)
{
//restart this TIMER
checkInputsMillis = millis();
checkInputs();
}
//********************************************
//other non-blocking code goes here
//********************************************
} //END of loop
//************************************************************************************
void checkInputs()
{
byte inputStatus;
//********************************************
inputStatus = digitalRead(RX);
//was there a change in sensor status ?
if (lastSensorStatus != inputStatus)
{
//update to the new state
lastSensorStatus = inputStatus;
//**********************
//has the signal disappeared ?
if (inputStatus == noSIGNAL)
{
digitalWrite(statusLED, LEDon);
//the time the object went into the IR beam
detectedMillis = millis();
}
//**********************
//the signal has returned
else
{
digitalWrite(statusLED, LEDoff);
Serial.print("Object was in beam for ");
Serial.print(millis() - detectedMillis);
Serial.println(" milliseconds.");
}
{
float elapsedTime = (millis() - detectedMillis);
float Speed = (Cardlength/1000)/(elapsedTime/1000);
Serial.print(Speed);
Serial.println("m/s");
}
}
} //END of checkInputs()
//************************************************************************************
Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
What, exact, LCD do you have? Is it I2C or parallel? 4 bit or 8 bit?
Have you tried to write the code? What happened? If you post the code (formatted properly and in code tags) we can help. We probably won't write it for you though.
We seldom see pretty code here. Just make sure to remove excess white space and use the IDE auto-format tool. That helps a lot.
Along with the code, please include a detailed description of what the code actually does and a description of what you expect the code to do. "My code doesn't work" conveys no useful information.
If there are compile errors, please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
So I am trying to just combine 2 codes to have both working at the same time (separately from each other). They both work when they're on their own but when I combine them, my LCD becomes a mess with random characters and the speed gate stops detecting signals.
#include <LiquidCrystal.h>
LiquidCrystal lcd (1, 8, 4, 5, 6, 7);
#define LEDon LOW
#define LEDoff HIGH
#define noSIGNAL HIGH
#define SIGNAL LOW
const byte TX = 3;
const byte statusLED = 13;
const byte RX = 2;
byte lastSensorStatus;
float Cardlength = 42.6;
//timing stuff
unsigned long checkInputsMillis;
unsigned long detectedMillis;
//************************************************************************************
void setup()
{
Serial.begin(9600);
pinMode(statusLED, OUTPUT);
digitalWrite(statusLED, LEDoff);
pinMode(TX, OUTPUT);
pinMode(RX, INPUT);
tone(TX, 38000);
lcd.begin(16, 2);
}
//************************************************************************************
void loop
()
{
//********************************************
//time to check the inputs (every 1ms) ?
if (millis() - checkInputsMillis >= 1)
{
//restart this TIMER
checkInputsMillis = millis();
checkInputs();
lcd.print ("Arduino");
delay (3000);
lcd.setCursor(2, 1);
lcd.print ("lcd tutorial");
delay (3000);
lcd.clear();
lcd.blink();
delay (4000);
lcd.setCursor(7, 1);
delay (3000);
lcd.noBlink();
lcd.cursor();
delay (4000);
lcd.noCursor();
lcd.clear();
}
} //END of loop
//************************************************************************************
void checkInputs()
{
byte inputStatus;
//********************************************
inputStatus = digitalRead(RX);
//was there a change in sensor status ?
if (lastSensorStatus != inputStatus)
{
//update to the new state
lastSensorStatus = inputStatus;
//**********************
//has the signal disappeared ?
if (inputStatus == noSIGNAL)
{
digitalWrite(statusLED, LEDon);
//the time the object went into the IR beam
detectedMillis = millis();
}
//**********************
//the signal has returned
else
{
digitalWrite(statusLED, LEDoff);
Serial.print("Object was in beam for ");
Serial.print(millis() - detectedMillis);
Serial.println(" milliseconds.");
}
{
float elapsedTime = (millis() - detectedMillis);
float Speed = (Cardlength / 1000) / (elapsedTime / 1000);
Serial.print(Speed);
Serial.println("m/s");
}
}
} //END of checkInputs()
//************************************************************************************
Small wonder, when you write to it 1000 times a second. EDIT - oh, wait, you have 17 seconds of delay() competing with millis() operation in loop(). That will never fly.
speed gate stops detecting signals
Small wonder, when you are spending 99% of your time twiddling your thumbs in delay() statements.
Pin 1 is the hardware serial (Serial) TX pin. Use a different pin for the RS. What happens once you make the pin change.
Please post the code in a new post if you change the code so that we can keep up.
Please post a schematic of your wiring (after fixing the LCD/Serial pin conflict). Written descriptions are always more ambiguous than a drawing. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.