Skip to content

Commit fccc271

Browse files
committed
support 1.4
1 parent 8ab1e6c commit fccc271

1 file changed

Lines changed: 28 additions & 24 deletions

File tree

11.app/balance_ball.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,37 @@
22
from random import randint
33
from machine import I2C, Pin
44
from mpu9250 import MPU9250
5+
56
i2c = I2C(scl=Pin(22), sda=Pin(21), freq=200000)
67
sensor = MPU9250(i2c)
78
print("MPU9250 id: " + hex(sensor.whoami))
8-
from display import NeoPixel, PixelPower
9+
from display import Pixel, PixelPower
10+
911
PixelPower(True)
10-
View = NeoPixel()
12+
View = Pixel()
1113
X, Y, Color, Flag = 2, 2, 2, 0
1214
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

Comments
 (0)