My team and I really need help with some coding. We have a project that requires the use of an optical sensor (Speed Detection 4 Pin 1CH Velocity Measurement Sensor Module 3.3-5V), we have a dc motor which we will attach a plastic circle with gaps and rotate it through the sensor, whereby, the LCD will not display.
So basically, do you have a code that I can try out?
This is what we have so far.
#include <LiquidCrystal.h> // for LCD to be included
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //pins connected to the arduino
int encoder_pin = 8;
unsigned int rpm;
volatile byte pulses;
unsigned long timeold;
unsigned int pulsesperturn = 1;
I see this a lot and have a question for those who know interrupts better than I do. Do the lines in the OP's code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //pins connected to the arduino
//...
attachInterrupt (0, counter, FALLING);
cause a problem? If interrupt vector 0 is associated with pin 2, do the statements above cause a conflict of some sort? Or, does the attachInterrupt() and resultant call to counter() override the lcd() momentarily, or is it simply not a problem?
do the statements above cause a conflict of some sort?
Of course they do.
Or, does the attachInterrupt() and resultant call to counter() override the lcd() momentarily
If the LiquidCrystal class declares that pin 2 is an OUTPUT, and changes the state of the pin now and then, the interrupt handler will be called every time the pin goes LOW. That is going to wreak havoc with the other (intended) use of the pin.
Thanks Paul(s). It confirms what I thought. Given that, I wonder why so many books and tutorials have the following object instantiation:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
This is the code the OP used, but in his defense, he took it from here which is the Arduino tutorial. I understand what pin 13 does, but why start the pin countdown with 12, then 11, then jump to 5? What makes 10-6 off limits? I try to avoid using 2 and 3 in these situations...just in case. I'm sure the people who wrote that Arduino tutorial have a good reason for this. I just don't know what it is.