|
2 | 2 | from random import randint |
3 | 3 | from machine import I2C, Pin |
4 | 4 | from mpu9250 import MPU9250 |
| 5 | + |
5 | 6 | i2c = I2C(scl=Pin(22), sda=Pin(21), freq=200000) |
6 | 7 | sensor = MPU9250(i2c) |
7 | 8 | print("MPU9250 id: " + hex(sensor.whoami)) |
8 | | -from display import NeoPixel, PixelPower |
| 9 | +from display import Pixel, PixelPower |
| 10 | + |
9 | 11 | PixelPower(True) |
10 | | -View = NeoPixel() |
| 12 | +View = Pixel() |
11 | 13 | X, Y, Color, Flag = 2, 2, 2, 0 |
12 | 14 | while True: |
13 | | - # print('acceleration:', sensor.acceleration) |
14 | | - # print('gyro:', sensor.gyro) |
15 | | - # print('magnetic:', sensor.magnetic) |
16 | | - A = sensor.acceleration # -1 and -2 Software correction |
17 | | - View.LoadXY(X, Y, (0, 0, 0)) |
18 | | - if(A[1] > -1 and A[1] > X and X < View.Max - 1): |
19 | | - X = X + 1 |
20 | | - elif(A[1] < -1 and A[1] < X and X > View.Min): |
21 | | - X = X - 1 |
22 | | - if(A[0] > -2 and A[0] > Y and Y > View.Min): |
23 | | - Y = Y - 1 |
24 | | - elif(A[0] < -2 and A[0] < Y and Y < View.Max - 1): |
25 | | - Y = Y + 1 |
26 | | - |
27 | | - Color = Color + Flag |
28 | | - if(Color == 10): Flag = -2 |
29 | | - elif(Color == 2): Flag = +2 |
30 | | - |
31 | | - View.LoadXY(X, Y, (0, Color, Color)) |
32 | | - View.Show() |
33 | | - utime.sleep_ms(100) |
34 | | - |
| 15 | + # print('acceleration:', sensor.acceleration) |
| 16 | + # print('gyro:', sensor.gyro) |
| 17 | + # print('magnetic:', sensor.magnetic) |
| 18 | + A = sensor.acceleration # -1 and -2 Software correction |
| 19 | + View.LoadXY(X, Y, (0, 0, 0), False) |
| 20 | + if (A[1] > -1 and A[1] > X and X < View.Max - 1): |
| 21 | + X = X + 1 |
| 22 | + elif (A[1] < -1 and A[1] < X and X > View.Min): |
| 23 | + X = X - 1 |
| 24 | + if (A[0] > -2 and A[0] > Y and Y > View.Min): |
| 25 | + Y = Y - 1 |
| 26 | + elif (A[0] < -2 and A[0] < Y and Y < View.Max - 1): |
| 27 | + Y = Y + 1 |
| 28 | + |
| 29 | + Color = Color + Flag |
| 30 | + if (Color == 10): |
| 31 | + Flag = -2 |
| 32 | + elif (Color == 2): |
| 33 | + Flag = +2 |
| 34 | + |
| 35 | + View.LoadXY(X, Y, (0, Color, Color), False) |
| 36 | + View.Show() |
| 37 | + utime.sleep_ms(100) |
| 38 | + |
0 commit comments