Created
October 14, 2015 14:40
-
-
Save s-celles/17a59c84e991251be5cb to your computer and use it in GitHub Desktop.
a mason's level using Raspberry Pi SenseHat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# coding: utf-8 | |
import sys | |
import time | |
from sense_hat import SenseHat | |
def limit(lcd_pos): | |
pos_lim = 6 | |
if lcd_pos < 0: | |
return 0 | |
if lcd_pos > pos_lim: | |
return pos_lim | |
return lcd_pos | |
def main(): | |
sense = SenseHat() | |
color = (255, 0, 0) | |
prev_x = -1 | |
prev_y = -1 | |
while True: | |
acc = sense.get_accelerometer_raw() | |
x = round(limit(-10 * acc['x'] + 3)) | |
y = round(limit(-10 * acc['y'] + 3)) | |
if x != prev_x or y != prev_y: | |
sense.clear() | |
sense.set_pixel(x, y, *color) | |
prev_x = x | |
prev_y = y | |
time.sleep(0.08) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment