Advertisement
learnelectronics

Arduino Foundation Series - SSD1306

Jul 25th, 2022
1,577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //#include <SPI.h>                                  //Not Needed if using I2c - SPI Driver for OLED
  3. #include <Wire.h>                                 //I2C Driver
  4. #include <Adafruit_GFX.h>                         //Graphics library
  5. #include <Adafruit_SSD1306.h>                     //SSD1306 OLED Driver
  6.  
  7. #define OLED_RESET 4                              //Digital pin 4 set aside for OLED reset
  8. Adafruit_SSD1306 display(OLED_RESET);             //We will call out OLED object display, but you can choose any name
  9.  
  10. int level = 0;                                    //INT variable for reading the pot on Analog 0
  11.  
  12.  
  13.  
  14.  
  15.  
  16. void setup() {                                    //SETUP - ONLY RUNS ONCE
  17.  
  18.   Serial.begin(9600);                             //Serial comms for debugging
  19.   display.begin(SSD1306_SWITCHCAPVCC, 0x3c);      //start the oled called display with a a hex addy of 0x3c
  20.   display.display();                              //Show what's in the buffer
  21.   delay(2000);                                    //take a breath
  22.   display.clearDisplay();                         //clear the screen
  23.   pinMode(A0,INPUT);                              //tell the nano to look for an analog signal on pin A0
  24.  
  25. }
  26.  
  27. void loop() {                                     //MAIN LOOP - RUNS OVER & OVER
  28.  
  29.  
  30. level = (analogRead(A0));                         //read the voltage on pin A0 and put the ADC value into variable level
  31.  
  32.  
  33.   display.clearDisplay();                         //always start with a clear
  34.   display.setTextSize(4);                         //set up text size
  35.   display.setTextColor(WHITE);                    //set text color
  36.   display.setCursor(10,10);                       //where to position cursor (128,64)
  37.   display.clearDisplay();                         //another flush
  38.   display.println(level);                         //add data in the buffer - the variable level
  39.   display.display();                              //show the buffer
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement