• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Wyświetlacz LCD brak komunikacji.
#21
Hej mam problem ze mi nie reaguje wyswietlacz nic sie nie wyswietla mam taki kod


#include <LiquidCrystal.h>

// Initialize LCD (adjust the pin numbers to your wiring)
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

// Define custom characters (for ball and paddle)
byte ballChar[8]  = { B00100, B01010, B00100, B00000, B00000, B00000, B00000, B00000 };
byte paddleChar[8] = { B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000 };

const int numCols = 16;
const int numRows = 2;

// Game object positions
int ballCol = 8;
int ballRow = 0;
int ballDX = 1;
int ballDY = 1;

// Paddle positions (assuming one-row paddles)
int leftPaddleRow  = 0;  // column 0
int rightPaddleRow = 0;  // column numCols-1

void setup() {
  lcd.begin(numCols, numRows);
  lcd.createChar(0, ballChar);  // index 0 for the ball
  lcd.createChar(1, paddleChar); // index 1 for the paddle

  // Initial drawing of the game state
  drawGame();
}

void loop() {
  // Update ball position
  ballCol += ballDX;
  ballRow += ballDY;

  // Bounce off top and bottom edges
  if (ballRow < 0 || ballRow >= numRows) {
    ballDY = -ballDY;
    ballRow += ballDY; // adjust after bounce
  }

  // Check collision with left paddle (column 0)
  if (ballCol == 0) {
    if (ballRow == leftPaddleRow) {
      ballDX = -ballDX;
      ballCol += ballDX;
    } else {
      // Right player scores; reset ball
      ballCol = numCols / 2;
      ballRow = numRows / 2;
    }
  }
 
  // Check collision with right paddle (last column)
  if (ballCol == numCols - 1) {
    if (ballRow == rightPaddleRow) {
      ballDX = -ballDX;
      ballCol += ballDX;
    } else {
      // Left player scores; reset ball
      ballCol = numCols / 2;
      ballRow = numRows / 2;
    }
  }

  // Read input here to update leftPaddleRow/rightPaddleRow for paddle movement

  // Redraw game objects on LCD
  drawGame();

  // Control the pace of the game
  delay(300); // Adjust delay for desired game speed
}

void drawGame() {
  lcd.clear();

  // Draw left paddle at column 0
  lcd.setCursor(0, leftPaddleRow);
  lcd.write(byte(1));
 
  // Draw right paddle at the far right column
  lcd.setCursor(numCols - 1, rightPaddleRow);
  lcd.write(byte(1));
 
  // Draw the ball
  lcd.setCursor(ballCol, ballRow);
  lcd.write(byte(0));
}

nie wiem w czym jest problem Huh
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości