Go Down

Topic: setcursors not working?? HELP (Read 37 times) previous topic - next topic

Aldertayy


Pls help me!! I can't seem to get setcursor to work. My bar graph keeps overlapping "This is your heartbeat" at the first line on the LCD screen.


#include <LiquidCrystal.h>
#include <LcdBarGraph.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //LiquidCrystal lcd(RS, Enable, D4, D5, D6, D7)
LcdBarGraph lbg(&lcd, 20);  // -- creating

//  Variables
int pulsePin = 0;                 // Pulse Sensor purple wire connected to analog pin 0 (A0)
int blinkPin = 13;                // pin to blink led at each beat
byte lcdNumCols = 20;             // -- number of columns in the LCD

// These variables are volatile because they are used in the interrupt service routine!
volatile int BPM;                   // int that holds the pulse rate. updated every 2mS
volatile int Signal;                // holds the incoming raw data
volatile int IBI = 600;             // int that holds the time interval between beats! Must be seeded!
volatile boolean Pulse = false;     // "True" when User's live heartbeat is detected. "False" when not a "live beat".
volatile boolean QS = false;        // becomes true when Arduoino finds a beat.
int temp;
int count = 0;


void setup(){
 
  lcd.begin(4, 20);
  pinMode(blinkPin,OUTPUT);         // pin that will blink to your heartbeat!             
  interruptSetup();                 // sets up to read Pulse Sensor signal every 2mS

void loop() {
  lcd.print("Time for your regular checkup!");
  delay(3000);
 
  lcd.clear();

  for (int i = 0; i < 1000; i++){
    lcd.setCursor(0,0);
    lcd.print("This is your hearbeat: ");
    lcd.print(BPM);
    lcd.setCursor(1,3);
    lbg.drawValue(BPM, 200);
   
    temp = BPM;
    delay(1000);

    for (int j = 0; j < 1500; j++){
     
      if (BPM == temp){
        count = count + 1;
        delay(1);
      }
     
    }

    if (count == 1500){
      lcd.clear();
      lcd.print("No heartbeat detected");
      delay(5000);
      lcd.clear();
      count = 0;
    }
   
    else if (BPM >100 || BPM < 30){
      count = 0;
      break;
    }
    delay(1000);
    lcd.clear();
    count = 0;
  }

 
  lcd.clear();

  if (BPM < 30){
    lcd.print("Your heartbeat is   too low! BPM: ");
    lcd.print(BPM);
   
    delay(5000);
    lcd.clear();
  }
  if (BPM > 100){
    lcd.print("Your heartbeat is too high! BPM: ");
    lcd.print(BPM);
   
   
    delay(5000);
    lcd.clear();
   
  }

ieee488

It seems you expect a 20 x 4 LCD to work like a 4 x 20 LCD.

I don't know if the LiquidCrystal library lets you do that.

.

Aldertayy

Yes I am using a 20 x 4 lcd. According to arduino website, LiquidCrystal allows the usage of setcursor, so I was suspecting that there is something wrong with the code? However, I can't seem to find the problem with the code.

groundFungus

Code: [Select]
 lcd.begin(4, 20);
The LiquidCrystal library reference for the begin function shows that the proper syntax is
Code: [Select]
lcd.begin(cols, rows);  // for a 20x4 display should be lcd.begin(20, 4)  

Go Up