Table of Contents

LED Control with Keys – Python

Example Description
The example demonstrates how to control the glowing LED using the keyboard keys in the Python Coding Environment.

Code

sprite = Sprite('Tobi')
quarky = Quarky()
import time

curr_x = 4
curr_y = 3
brightness = 50

quarky.cleardisplay()
quarky.setled(curr_x, curr_y, (0, 255, 0), brightness)

while True:
  
  if sprite.iskeypressed("up arrow"):
    curr_y = curr_y - 1
    quarky.setled(curr_x, curr_y + 1, (0, 0, 0), brightness)
    time.sleep(0.2)
    quarky.setled(curr_x, curr_y, (0, 255, 0), brightness)

  if sprite.iskeypressed("down arrow"):
    curr_y = curr_y + 1
    quarky.setled(curr_x, curr_y - 1, (0, 0, 0), brightness)
    time.sleep(0.2)
    quarky.setled(curr_x, curr_y, (0, 255, 0), brightness)
    
  if sprite.iskeypressed("left arrow"):
    curr_x = curr_x - 1
    quarky.setled(curr_x + 1, curr_y, (0, 0, 0), brightness)
    time.sleep(0.2)
    quarky.setled(curr_x, curr_y, (0, 255, 0), brightness)
    
  if sprite.iskeypressed("right arrow"):
    curr_x = curr_x + 1
    quarky.setled(curr_x - 1, curr_y, (0, 0, 0), brightness)
    time.sleep(0.2)
    quarky.setled(curr_x, curr_y, (0, 255, 0), brightness)
  
  time.sleep(0.2)