Advertisement
microrobotics

Untitled

Aug 3rd, 2023
1,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. # Import necessary libraries
  2. import time
  3. import pew
  4.  
  5. # Initialize PewPew Gaming Console
  6. pew.init()
  7.  
  8. # Initialize the dot's position
  9. dot_x, dot_y = 3, 3
  10.  
  11. # Main loop
  12. while True:
  13.     # Clear the LED grid
  14.     pew.pixels.fill((0, 0, 0))
  15.  
  16.     # Display the dot at its current position
  17.     pew.pixels[dot_x, dot_y] = (255, 0, 0)
  18.  
  19.     # Update the LED display
  20.     pew.show()
  21.  
  22.     # Delay for a short period to control the dot's speed
  23.     time.sleep(0.2)
  24.  
  25.     # Check button presses and move the dot accordingly
  26.     keys = pew.keys()
  27.     if keys & pew.K_UP:
  28.         dot_y = max(dot_y - 1, 0)
  29.     if keys & pew.K_DOWN:
  30.         dot_y = min(dot_y + 1, 7)
  31.     if keys & pew.K_LEFT:
  32.         dot_x = max(dot_x - 1, 0)
  33.     if keys & pew.K_RIGHT:
  34.         dot_x = min(dot_x + 1, 7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement