45 lines
964 B
Arduino
45 lines
964 B
Arduino
|
|
#include <Wire.h>
|
||
|
|
#include <Adafruit_GFX.h>
|
||
|
|
#include <Adafruit_SSD1306.h>
|
||
|
|
#include <Fonts/FreeMono9pt7b.h>
|
||
|
|
|
||
|
|
#define POTENTIOMETER_IN A0
|
||
|
|
#define SCREEN_WIDTH 128
|
||
|
|
#define SCREEN_HEIGHT 64
|
||
|
|
|
||
|
|
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
|
||
|
|
|
||
|
|
int i, wave = 0;
|
||
|
|
|
||
|
|
void setup() {
|
||
|
|
Serial.begin(115200);
|
||
|
|
|
||
|
|
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
|
||
|
|
Serial.println("SSD1306 allocation failed");
|
||
|
|
for (;;);
|
||
|
|
}
|
||
|
|
delay(2000);
|
||
|
|
|
||
|
|
display.setFont(&FreeMono9pt7b);
|
||
|
|
display.clearDisplay();
|
||
|
|
display.setTextSize(1);
|
||
|
|
display.setTextColor(WHITE);
|
||
|
|
display.setCursor(0, 20);
|
||
|
|
display.println("Shved\nAndrii\nIO-23");
|
||
|
|
display.display();
|
||
|
|
delay(3000);
|
||
|
|
}
|
||
|
|
|
||
|
|
void loop() {
|
||
|
|
display.clearDisplay();
|
||
|
|
|
||
|
|
for (i = 0; i < SCREEN_WIDTH; ++i) {
|
||
|
|
wave = analogRead(POTENTIOMETER_IN);
|
||
|
|
wave = map(wave, 0, 1023, SCREEN_HEIGHT - 1, 0);
|
||
|
|
wave = constrain(wave, 0, SCREEN_HEIGHT);
|
||
|
|
|
||
|
|
display.drawPixel(i, wave, WHITE);
|
||
|
|
display.display();
|
||
|
|
}
|
||
|
|
}
|