Hello,
I'm trying to merge code of two workings programs:
- the first count using a sensor
- the second prints on a LCD screen
So I tried to display the sensor count on the LCD.
On the setup() function I can print out on the LCD the string "INIT".
On the loop() function, I can print only ONCE on the LCD because after the sei() and cli() call everything stops working.
Can you please explain me how to make it work?
Thanks!
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int NbTopsFan;
int calc;
int hallsensor = 2;
LiquidCrystal_I2C lcd(0x27,16,2);
void rpm()
{
NbTopsFan++;
}
void setup()
{
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
// Works fine: the LCS print INIT each time
lcd.print("INIT");
pinMode(hallsensor,INPUT);
Serial.begin(9600);
attachInterrupt(0, rpm, RISING);
}
void loop()
{
// The LCS print TEST1 each time
lcd.setCursor(0,1);
lcd.print("TEST1");
NbTopsFan = 0;
sei();
delay(1000);
cli();
calc=(NbTopsFan * 2.2);
Serial.println(calc,DEC);
// DOES NOT print Test2
lcd.setCursor(0,1);
lcd.print("TEST2");
}