Go Down

Topic: Knight rider light bar with lcd bar graph (Read 1 time) previous topic - next topic

MillerJLee98579


MillerJLee98579

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

BillHo

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

MillerJLee98579


#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

MillerJLee98579

Quote

#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?

Go Up