Knight rider light bar with lcd bar graph

So I’m trying to get the coding right for this and I seem to have hit a snag and I can not figure out why is wrong. Here is my code so far

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

byte lcdNumCols = 16; // – number of columns in the LCD
byte sensorPin = 0; // – value for this example

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // – creating LCD instance
LcdBarGraph lbg(&lcd, lcdNumCols); // – creating

void setup(){
// – initializing the LCD
lcd.begin(2, lcdNumCols);
lcd.clear();
// – do some delay: some time I’ve got broken visualization
delay(100);
}

void loop()
{
// – draw bar graph from the analog value readed
lbg.drawValue( analogRead(sensorPin), 1024);
// – do some delay: frequent draw may cause broken visualization
delay(100);

}
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
}

void loop() {

sensorValue = analogRead(sensorPin);
digitalWrite(3, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(5, HIGH);
digitalWrite(1, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(5, LOW);
digitalWrite(1, LOW);
digitalWrite(6, HIGH);
digitalWrite(0, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(6, LOW);
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(5, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(1, LOW);
digitalWrite(5, LOW);
digitalWrite(2, HIGH);
digitalWrite(4, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(2, LOW);
digitalWrite(4, LOW);
}

AnalogVisualization.pde:-1: error: conflicting declaration 'int sensorPin' AnalogVisualization.pde:-1: error: 'sensorPin' has a previous declaration as 'byte sensorPin' AnalogVisualization.cpp: In function 'void setup()': AnalogVisualization.pde:-1: error: redefinition of 'void setup()' AnalogVisualization.pde:-1: error: 'void setup()' previously defined here AnalogVisualization.cpp: In function 'void loop()': AnalogVisualization.pde:-1: error: redefinition of 'void loop()' AnalogVisualization.pde:-1: error: 'void loop()' previously defined here

and these are the error messages I am getting. Pins 0-6 ar for my LED's and the screen is on pins 9-13. The LCD I am using is a SSD1306 from adafruit.com

Compilation errors. I guess this is the first C program you ever wrote.

error: conflicting declaration 'int sensorPin' sensorPin is declared twice; remove this line: byte sensorPin = 0; // -- value for this example

error: redefinition of 'void setup()' merge the content of the 2 setup functions (and leave just one)

error: redefinition of 'void loop()' merge the content of the 2 loop functions (and leave just one)

Here are example of the merge code.

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

/*
The circuit:
 * LCD RS pin to digital pin 13
 * LCD Enable pin to digital pin 12
 * LCD D4 pin to digital pin 11
 * LCD D5 pin to digital pin 10
 * LCD D6 pin to digital pin 9
 * LCD D7 pin to digital pin 8
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
*/

byte lcdNumCols = 16; // -- number of columns in the LCD
// byte sensorPin = 0; // -- value for this example
int sensorPin = A0; // select the input pin for the potentiometer
//int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // -- creating LCD instance
LcdBarGraph lbg(&lcd, lcdNumCols);  // -- creating

void setup(){
  // -- initializing the LCD
  lcd.begin(2, lcdNumCols);
  lcd.clear();
  // -- do some delay: some time I've got broken visualization
  delay(100);
	pinMode(6, OUTPUT);
	pinMode(5, OUTPUT);
	pinMode(4, OUTPUT);
	pinMode(3, OUTPUT);
	pinMode(2, OUTPUT);
	pinMode(1, OUTPUT);
	pinMode(0, OUTPUT);

}


void loop()
{
  // -- draw bar graph from the analog value readed
  lbg.drawValue( analogRead(sensorPin), 1024);
  // -- do some delay: frequent draw may cause broken visualization
  delay(100);
	sensorValue = analogRead(sensorPin);
	digitalWrite(3, HIGH);
	delay(sensorValue);
	sensorValue = analogRead(sensorPin);
	digitalWrite(3, LOW);
	digitalWrite(4, HIGH);
	digitalWrite(2, HIGH);
	delay(sensorValue);
	sensorValue = analogRead(sensorPin);
	digitalWrite(4, LOW);
	digitalWrite(2, LOW);
	digitalWrite(5, HIGH);
	digitalWrite(1, HIGH);
	delay(sensorValue);
	sensorValue = analogRead(sensorPin);
	digitalWrite(5, LOW);
	digitalWrite(1, LOW);
	digitalWrite(6, HIGH);
	digitalWrite(0, HIGH);
	delay(sensorValue);
	sensorValue = analogRead(sensorPin);
	digitalWrite(6, LOW);
	digitalWrite(0, LOW);
	digitalWrite(1, HIGH);
	digitalWrite(5, HIGH);
	delay(sensorValue);
	sensorValue = analogRead(sensorPin);
	digitalWrite(1, LOW);
	digitalWrite(5, LOW);
	digitalWrite(2, HIGH);
	digitalWrite(4, HIGH);
	delay(sensorValue);
	sensorValue = analogRead(sensorPin);
	digitalWrite(2, LOW);
	digitalWrite(4, LOW);
}

Thank you for the help, but I am still having a problem with the LCD pin set up. The pins on my display are labeled, ground (pin1), 3.3vc(pin2), Vin(pin3), DATA(pin4), CLK(pin5), D/C(pin6), RST(pin7) and CS(pin8). After i redid the wires per your instruction and uploaded the code it still did not work did i do something wrong?

https://www.adafruit.com/products/661 this is the LCD screen I'm using for the bar graph

Update the LED's are working now but I still have no display from the LCD please help.

SSD1306 from adafruit.com is not LCD that used in LiquidCrystal Libraries which using HD44780.

You can download our SSD1306 OLED display Arduino library from github and follow the example

#include <Adafruit_SSD1306.h>
#include <LcdBarGraph.h>

/*
The circuit:

  • LCD RS pin to digital pin 13
  • LCD Enable pin to digital pin 12
  • LCD D4 pin to digital pin 11
  • LCD D5 pin to digital pin 10
  • LCD D6 pin to digital pin 9
  • LCD D7 pin to digital pin 8
  • LCD R/W pin to ground
  • 10K resistor:
  • ends to +5V and ground
  • wiper to LCD VO pin (pin 3)
    */

byte lcdNumCols = 16; // – number of columns in the LCD
// byte sensorPin = 0; // – value for this example
int sensorPin = A0; // select the input pin for the potentiometer
//int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup(){
// – initializing the LCD

// – do some delay: some time I’ve got broken visualization
delay(1);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);

}

void loop()
{
// – draw bar graph from the analog value readed

// – do some delay: frequent draw may cause broken visualization
delay(100);
sensorValue = analogRead(sensorPin);
digitalWrite(3, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(5, HIGH);
digitalWrite(1, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(5, LOW);
digitalWrite(1, LOW);
digitalWrite(6, HIGH);
digitalWrite(0, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(6, LOW);
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(5, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(1, LOW);
digitalWrite(5, LOW);
digitalWrite(2, HIGH);
digitalWrite(4, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
}

OK this is what I have and trying to use the example really isnt helping much since i just started learning C. Please help me get this code to work and display a bar graph

#define OLED_DC 11
#define OLED_CS 12
#define OLED_CLK 10
#define OLED_MOSI 9
#define OLED_RESET 13

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

Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

int sensorPin = A0; // select the input pin for the potentiometer
//int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup(){

display.begin(SSD1306_SWITCHCAPVCC);
// init done

display.display(); // show splashscreen
delay(2000);
display.clearDisplay(); // clears the screen and buffer
delay(10);

pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);

}

void loop()
{
sensorValue = analogRead(sensorPin);
digitalWrite(3, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(2, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(5, HIGH);
digitalWrite(1, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(5, LOW);
digitalWrite(1, LOW);
digitalWrite(6, HIGH);
digitalWrite(0, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(6, LOW);
digitalWrite(0, LOW);
digitalWrite(1, HIGH);
digitalWrite(5, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(1, LOW);
digitalWrite(5, LOW);
digitalWrite(2, HIGH);
digitalWrite(4, HIGH);
delay(sensorValue);
sensorValue = analogRead(sensorPin);
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(3, HIGH);
}

OK this is the new code so far can you show me how to implement a bar graph with this?

I'm still stuck on the bar graph coding for this any help would be appreciated. I'm using a ssd1306 128x32 lcd screen from adafruit and so far i have everything done but the code to generate the bar graph

Does anyone know how to write a bar graph code for this particular LCD?

Update! Thanks to the nice support of the folks at adafruit I managed to get the bar graph code working, but it has drastically changed the blink rates of my LED’s and no longer functions the same as the original. As I am new to this programming language I would like to ask if someone could please give me an example of how to incorporate the timer library into this sketch

#define OLED_DC 11
    #define OLED_CS 12
    #define OLED_CLK 10
    #define OLED_MOSI 9
    #define OLED_RESET 13

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

    Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

    int sensorPin = A0; // select the input pin for the potentiometer
    //int ledPin = 13; // select the pin for the LED
    int sensorValue = 0; // variable to store the value coming from the sensor



    void setup(){

    display.begin(SSD1306_SWITCHCAPVCC);
      // init done
     
      display.display(); // show splashscreen
      delay(10);
      display.clearDisplay();   // clears the screen and buffer
      delay(10);
     
      display.setTextSize(5);
      display.setTextColor(WHITE);
      display.println("KITT");
      display.display();
      delay(10);
     


       pinMode(6, OUTPUT);
       pinMode(5, OUTPUT);
       pinMode(4, OUTPUT);
       pinMode(3, OUTPUT);
       pinMode(2, OUTPUT);
       pinMode(1, OUTPUT);
       pinMode(0, OUTPUT);

    }


    void loop()
    {
              // Read analog input:
    sensorValue = analogRead(sensorPin);
    // Scale input to width of display:
    int w = map(sensorValue, 0, 1023, 0, display.width());
       // Draw filled part of bar starting from left of screen:
    display.fillRect(0, 0, w, display.height(), 1);
       // Erase the area to the right of the bar:
    display.fillRect(w, 0, display.width() - w, display.height(), 0);
    // Update the screen:
    display.display();
 

       sensorValue = analogRead(sensorPin);
       digitalWrite(3, HIGH);
       delay(sensorValue);
       sensorValue = analogRead(sensorPin);
       digitalWrite(3, LOW);
       digitalWrite(4, HIGH);
       digitalWrite(2, HIGH);
       delay(sensorValue);
       sensorValue = analogRead(sensorPin);
       digitalWrite(4, LOW);
       digitalWrite(2, LOW);
       digitalWrite(5, HIGH);
       digitalWrite(1, HIGH);
       delay(sensorValue);
       sensorValue = analogRead(sensorPin);
       digitalWrite(5, LOW);
       digitalWrite(1, LOW);
       digitalWrite(6, HIGH);
       digitalWrite(0, HIGH);
       delay(sensorValue);
       sensorValue = analogRead(sensorPin);
       digitalWrite(6, LOW);
       digitalWrite(0, LOW);
       digitalWrite(1, HIGH);
       digitalWrite(5, HIGH);
       delay(sensorValue);
       sensorValue = analogRead(sensorPin);
       digitalWrite(1, LOW);
       digitalWrite(5, LOW);
       digitalWrite(2, HIGH);
       digitalWrite(4, HIGH);
       delay(sensorValue);
       sensorValue = analogRead(sensorPin);
       digitalWrite(2, LOW);
       digitalWrite(4, LOW);
       digitalWrite(3, HIGH);
       delay(sensorValue);
    }