Moving a flat surface left and right with a potentiometer

17 Views Asked by At

I want to draw a flat surface on my OLED screen connected to Ardunio Mega and move it left and right with the potentiometer. I wrote the code below, but I couldn't draw a flat surface on the screen, can you help me?

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

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

const int potPin = A0; 
int potValue = 0; 
int paddleX = 0; 

void setup() {
Serial.begin(9600); 

display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 
display.clearDisplay(); 
}

void loop() {
potValue = analogRead(potPin); 
paddleX = map(potValue, 0, 1023, 0, 128); 
Serial.println(paddleX); 

display.clearDisplay();

display.fillRect(paddleX, 56, 32, 8, WHITE);

display.display();

delay(100);
0

There are 0 best solutions below