Making a graph on LCD Screen

Hello,

For a project in school , i need to do several things but I had a problem with one in particular. Basically i have a xd_58c captor that mesures pulse rate and we have to had a buzzer , some leds and other stuff but we also have to display on a LCD screen the hours and if the captor is used , shows a graph from the captor on top and the values on the bottom. I don't really know how to it so if you could help me it would be nice.

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH,SCREEN_HEIGHT,&Wire,-1);



#define Battementmax 550
#define BattementMin 500

bool TempsBPM=false;
bool BattementComplet=false;
int DernierBattement=0;
int BPM=0;
int faux=0;

void ecran(int valeur , int temps);
 
void setup() {
  Serial.begin(9600);
}
 
 
void loop() 
{
  
  int temps;
  Serial.println(analogRead(0));
   
 
  faux=analogRead(0);
  BPM=map(faux,0,1023,0,160);
  // calc bpm
  
  if(BPM>Battementmax)
  {
    if(BattementComplet)
    {
      BPM=millis()-DernierBattement;
      BPM=int(60/(float(BPM)/10000));
      TempsBPM=false;
      BattementComplet=false;
    }
    if(TempsBPM==false)
    {
      DernierBattement=millis();
      TempsBPM=true;
    }
  }
  if((BPM<BattementMin)&(TempsBPM))
    BattementComplet=true;
    // output bpm to serial monitor
  Serial.print(BPM);
  Serial.println("BPM");
  delay(1000);

ecran(BPM,temps);
  
}

void ecran(int valeur, int temps)
{
display.clearDisplay();

display.setTextColor(WHITE);
display.setTextSize(2);
display.setCursor(0,10);
display.print(BPM);
display.setCursor(30,30);
Serial.print(analogRead(0));
  
}

The last bit is all I know and got taught about displaying stuff on a LCD screen.

other ssd1306 libraries have drawLine(), drawRect(),drawCircle(), ... see (look at the .h) to see if the library you have similar functions and if not, find another library that does

google for an example that draws graphics on a 1306 oled

gcjr:
other ssd1306 libraries have drawLine(), drawRect(),drawCircle(), ... see (look at the .h) to see if the library you have similar functions and if not, find another library that does

google for an example that draws graphics on a 1306 oled

Well I found this ,

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH,SCREEN_HEIGHT,&Wire,-1);



#define Battementmax 550
#define BattementMin 500
bool Redraw1 = true;
bool TempsBPM=false;
bool BattementComplet=false;
int DernierBattement=0;
int BPM=0;
int faux=0;

void ecran(int valeur , int temps);
 
void setup() {
  Serial.begin(9600);
}
 
 
void loop() 
{
  
  int temps;
  Serial.println(analogRead(0));
   
 
  faux=analogRead(0);
  BPM=map(faux,0,1023,0,160);
  // calc bpm
  
  if(BPM>Battementmax)
  {
    if(BattementComplet)
    {
      BPM=millis()-DernierBattement;
      BPM=int(60/(float(BPM)/10000));
      TempsBPM=false;
      BattementComplet=false;
    }
    if(TempsBPM==false)
    {
      DernierBattement=millis();
      TempsBPM=true;
    }
  }
  if((BPM<BattementMin)&(TempsBPM))
    BattementComplet=true;
    // output bpm to serial monitor
  Serial.print(BPM);
  Serial.println("BPM");
  delay(1000);

ecran(display, BPM, 5,  60, 10, 40, 0, 1024 , 256, 0, "Signal", Redraw1);
  
}

void ecran(Adafruit_SSD1306 &d, double curval, double x , double y , double w, double h , double loval , double hival , double inc , double dig, String label, bool &Redraw)
{
  double stepval, my, level, i, data;

  if (Redraw) {
    Redraw = false;
    d.fillRect(0, 0,  127 , 14, SSD1306_WHITE);
    d.setTextColor(SSD1306_BLACK, SSD1306_WHITE);
    d.setTextSize(1);
    d.setCursor(2, 4);
    d.println(label);
    // step val basically scales the hival and low val to the height
    // deducting a small value to eliminate round off errors
    // this val may need to be adjusted
    stepval = ( inc) * (double (h) / (double (hival - loval))) - .001;
    for (i = 0; i <= h; i += stepval) {
      my =  y - h + i;
      d.drawFastHLine(x + w + 1, my,  5, SSD1306_WHITE);
      // draw lables
      d.setTextSize(1);
      d.setTextColor(SSD1306_WHITE, SSD1306_BLACK);
      d.setCursor(x + w + 12, my - 3 );
      data = hival - ( i * (inc / stepval));
      d.print(data, dig);
    }
  }
  // compute level of bar graph that is scaled to the  height and the hi and low vals
  // this is needed to accompdate for +/- range
  level = (h * (((curval - loval) / (hival - loval))));
  // draw the bar graph
  // write a upper and lower bar to minimize flicker cause by blanking out bar and redraw on update
  d.drawRect(x, y - h, w, h, SSD1306_WHITE);
  d.fillRect(x, y - h, w, h - level,  SSD1306_BLACK);
  d.drawRect(x, y - h, w, h, SSD1306_WHITE);
  d.fillRect(x, y - level, w,  level, SSD1306_WHITE);
  // up until now print sends data to a video buffer NOT the screen
  // this call sends the data to the screen
  d.display();

}

But it seems a little bit too sophisticated for someone new to arduino like me and i didn't find anything really less "difficult"

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.