Display and reading analog pots. Multiple readings..graphs,bars

Hello.

My project its a midi footswitch,but now i am working on the display part.

I am not a programmer and i don´t have idea what could i achieve with a display yet,,so every help would be appreciated.

I have found this code and its working really well..
It shows a bar, rising or decreasing, from zero to 20 when its reading a pot, connected to pin A0..
Also.. it shows a number between 0-5,when its reading (the pot connected to pin A0)

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LcdBarGraphRobojax.h>


byte lcdNumCols = 20; // -- number of columns in the LCD
byte lcdLine = 4; // -- number of line in the LCD
byte sensorPin = 0; // -- value for this example
byte sensorPin2 = 1;
LiquidCrystal_I2C lcd (0x27,lcdNumCols,lcdLine);  // -- creating LCD instance
LcdBarGraphRobojax lbg(&lcd, 20, 0, 0);  // -- creating 16 character long bargraph starting at char 0 of line 0 (see video)
     
void setup()
{
  // -- initializing the LCD
   lcd.init();                      // initialize the lcd 
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.clear();
  lcd.print("PEDALERA ELIAS"); 
  lcd.setCursor (0,3); //  
  lcd.print("voltage Bargraph"); 
  
  // -- do some delay: some time I've got broken visualization
  delay(1000);
  lcd.clear(); 
}

void loop()
{
  lbg.clearLine(1);// clear line 1 to display fresh voltage value
  int inpuValue = analogRead(sensorPin);
  // -- draw bar graph from the analog value read
  lbg.drawValue( inpuValue, 1024);
  // -- do some delay: frequent draw may cause broken visualization
  float GAIN = inpuValue * (5.0 / 1023.0);
  lcd.setCursor (0,3); //
  lcd.print("GAIN:"); 
  lcd.setCursor (8,3); //
  lcd.print(GAIN); // print
  lcd.setCursor (12,1); //  
  lcd.print("");   
 
  delay(100);
}

Link for the source

My question its about reading multiple pots, because i don´t know how to achieve it..now i am only able to reading one pot.
My wish its I want to show on the screen the "pot1" values when i move the "pot1", but after 3 seconds of no reading i want to switch off the screen or wait for another pot reading.. , and then the screen will show another pot when its reading (A0, A1 etc..).

And I got another question about creating new chars..
i have found this code

//YWROBOT

//Compatible with the Arduino IDE 1.0

//Library version:1.1

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>

#include "RunningAverage.h"



RunningAverage myRA(10);
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

const int whichPort = A1;

// Variables will change:

int vol = 0;   // counter for the number of button presses
int lastVol = -1;
int samples = 0;

byte LT[8] = 

{



  B00111,

  B01111,

  B11111,

  B11111,

  B11111,

  B11111,

  B11111,

  B11111

};

byte UB[8] =

{

  B11111,

  B11111,

  B11111,

  B00000,

  B00000,

  B00000,

  B00000,

  B00000

};

byte RT[8] =

{



  B11100,

  B11110,

  B11111,

  B11111,

  B11111,

  B11111,

  B11111,

  B11111

};

byte LL[8] =

{



  B11111,

  B11111,

  B11111,

  B11111,

  B11111,

  B11111,

  B01111,

  B00111

};

byte LB[8] =

{

  B00000,

  B00000,

  B00000,

  B00000,

  B00000,

  B11111,

  B11111,

  B11111

};

byte LR[8] =

{



  B11111,

  B11111,

  B11111,

  B11111,

  B11111,

  B11111,

  B11110,

  B11100

};

byte MB[8] =

{

  B11111,

  B11111,

  B11111,

  B00000,

  B00000,

  B00000,

  B11111,

  B11111

};

byte block[8] =

{

  B11111,

  B11111,

  B11111,

  B11111,

  B11111,

  B11111,

  B11111,

  B11111

};



void setup()

{

  

  Serial.begin(9600);

  lcd.init();                      // initialize the lcd 

  lcd.createChar(0,LT);

  lcd.createChar(1,UB);

  lcd.createChar(2,RT);

  lcd.createChar(3,LL);

  lcd.createChar(4,LB);

  lcd.createChar(5,LR);

  lcd.createChar(6,MB);

  lcd.createChar(7,block);

  

  // Print a message to the LCD.

  lcd.backlight();

   

  lcd.clear();



  displayNumber();

   

}



void printNumber(int val){

  

     int col=5;     

     

     if( val >= 10){

       printDigits(val/10,col);     

       printDigits(val%10,col+4);

     }

     else{

       printDigits(val,col);

     }

}



void loop()

{




   vol = analogRead(whichPort);            // reads the value of the potentiometer (value between 0 and 1023)

   vol = map(vol, 0, 1023, 0, 10); 



    myRA.addValue(vol );

    samples++; 

      



   if (samples == 300)

  {

    vol = myRA.getAverage();

    if( lastVol != vol ){      

      Serial.println( vol );

       lastVol = vol;

       displayNumber();

       delay(300);

    }

    samples = 0;

    myRA.clear();

    

  }



  



  

}

void displayNumber(){

    

    lcd.clear();

    lcd.setCursor(0,0);

    lcd.print("Vol:"); 

    printNumber( vol );

    

}

void custom0(int x){ 



  lcd.setCursor(x,0); 

  lcd.write(0);  

  lcd.write(1);  

  lcd.write(2);

  lcd.setCursor(x, 1); 

  lcd.write(3);  

  lcd.write(4);  

  lcd.write(5);

}



void custom1(int x){

  lcd.setCursor(x,0);

  lcd.write(1);

  lcd.write(2);

  

  lcd.print(" ");

  lcd.setCursor(x,1);

  lcd.write(4);

  lcd.write(7);

  lcd.write(4);

}



void custom2(int x){

  lcd.setCursor(x,0);

  lcd.write(6);

  lcd.write(6);

  lcd.write(2);

  lcd.setCursor(x, 1);

  lcd.write(3);

  lcd.write(4);

  lcd.write(4);

}



void custom3(int x){

  lcd.setCursor(x,0);

  lcd.write(6);

  lcd.write(6);

  lcd.write(2);

  lcd.setCursor(x, 1);

  lcd.write(4);

  lcd.write(4);

  lcd.write(5); 

}



void custom4(int x){

  lcd.setCursor(x,0);

  lcd.write(3);

  lcd.write(4);

  lcd.write(7);

  lcd.setCursor(x, 1);

  lcd.print(" ");

  lcd.print(" ");

  lcd.write(7);

}



void custom5(int x){

  lcd.setCursor(x,0);

  lcd.write(3);

  lcd.write(6);

  lcd.write(6);

  lcd.setCursor(x, 1);

  lcd.write(4);

  lcd.write(4);

  lcd.write(5);

}



void custom6(int x){

  lcd.setCursor(x,0);

  lcd.write(0);

  lcd.write(6);

  lcd.write(6);

  lcd.setCursor(x, 1);

  lcd.write(3);

  lcd.write(4);

  lcd.write(5);

}



void custom7(int x){

  lcd.setCursor(x,0);

  lcd.write(1);

  lcd.write(1);

  lcd.write(2);

  lcd.setCursor(x, 1);

  lcd.print(" ");

  lcd.print(" ");

  lcd.write(7);

}



void custom8(int x){

  lcd.setCursor(x,0);

  lcd.write(0);

  lcd.write(6);

  lcd.write(2);

  lcd.setCursor(x, 1);

  lcd.write(3);

  lcd.write(4);

  lcd.write(5);

}



void custom9(int x){

  

  lcd.setCursor(x,0);

  lcd.write(0);

  lcd.write(6);

  lcd.write(2);

  lcd.setCursor(x, 1);

  lcd.print(" ");

  lcd.print(" ");

  lcd.write(7);



}

void printDigits(int digits, int x){

  // utility function for digital clock display: prints preceding colon and leading 0



  switch (digits) {

  case 0:  

    custom0(x);

    break;

  case 1:  

    custom1(x);

    break;

  case 2:  

    custom2(x);

    break;

  case 3:  

    custom3(x);

    break;

  case 4:  

    custom4(x);

    break;

  case 5:  

    custom5(x);

    break;

  case 6:  

    custom6(x);

    break;

  case 7:  

    custom7(x);

    break;

  case 8:  

    custom8(x);

    break;

  case 9:  

    custom9(x);

    break;

  }
}

Youtube link for the source
So..this code..its interesting...its the same thing than the first code..but now the words "gain" changes to "vol" and the graph-bar its reemplaced by big numbers (two lines big numbers). And changes the range numbers..now its between 0-10 (the first code was between 0-5)
Its the same thing..but now its for reading a pot connected to A0 (the first code was for A1 pin).
No graph bar..but big numbers...i like it

My question its arduino could manage this two graphs at the same time? i mean to show the graphbar (the first code) on the 4th line and the big numbers (second code)on lines 1st and 2nd....i mean to showing two graphs at the same time..its possible?

Thanks

Interesting set of problems. It would help us if you posted a complete schematic, not a frizzy drawing showing all power and ground connections including power supply(s). I would suggest play with the blink without delay and learn how not to use the delah() instruction, it locks up everything. There are many good tutorials on line as well as the Arduino cookbook is available for purchase.

This topic was automatically closed after 68 days. New replies are no longer allowed.