Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Reads the gyro sensor, and displays a '+' accordingly
- # Copyright 2023, 2024 Roland Richter [Mu: BBC micro:bit]
- import microbit
- def compute_position(value):
- if value < -600:
- return 0
- elif value < -200:
- return 1
- elif value < 200:
- return 2
- elif value < 600:
- return 3
- else:
- return 4
- # Draw a vertical line at column c (between 0 and 4)
- def draw_vertical_line(c):
- microbit.display.set_pixel(c, 0, 9)
- microbit.display.set_pixel(c, 1, 9)
- microbit.display.set_pixel(c, 2, 9)
- microbit.display.set_pixel(c, 3, 9)
- microbit.display.set_pixel(c, 4, 9)
- # Draw a horizontal line at row r (between 0 and 4)
- def draw_horizontal_line(r):
- microbit.display.set_pixel(0, r, 9)
- microbit.display.set_pixel(1, r, 9)
- microbit.display.set_pixel(2, r, 9)
- microbit.display.set_pixel(3, r, 9)
- microbit.display.set_pixel(4, r, 9)
- while True:
- microbit.display.clear()
- x_val = microbit.accelerometer.get_x()
- col = compute_position(x_val)
- y_val = microbit.accelerometer.get_y()
- row = compute_position(y_val)
- draw_vertical_line(col)
- draw_horizontal_line(row)
- microbit.sleep(100)
- # ----------------------------------------------------------------------
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program. If not, see <https://www.gnu.org/licenses/>.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement