コード例 #1
0
 def collide_detect(self):
     self.player_x = 64 - -cyberpi.get_roll()
     self.player_y = 64 - -cyberpi.get_pitch()
     if self.player_x < 0:
         self.player_x = 5
     if self.player_x > 128:
         self.player_x = 123
     if self.player_y < 0:
         self.player_y = 5
     if self.player_y > 128:
         self.player_y = 123
     self.player.move_to(self.player_x, self.player_y)
コード例 #2
0
难度:⭐⭐⭐⭐⭐
支持的模式:在线模式
无

"""
# ---------程序分割线----------------程序分割线----------------程序分割线----------

import cyberpi
import time
from matplotlib import pyplot as plt

plt.rcParams['font.sans-serif'] = ['Microsoft YaHei']
plt.ion()
plt.figure(figsize=(15, 8))

while True:
    hum = cyberpi.humiture.get_humidity()
    temp = cyberpi.humiture.get_temp()
    plt.clf()
    y_locator = plt.MultipleLocator(10)
    x_locator = plt.MultipleLocator(10)
    ax=plt.gca()
    ax.yaxis.set_major_locator(y_locator)
    ax.xaxis.set_major_locator(x_locator)
    plt.ylim(-90,90)
    plt.xlim(-180,180)
    plt.scatter(x=0+cyberpi.get_roll(), y=0+cyberpi.get_pitch())
    plt.title('跟随陀螺仪变化位置的小点')
    plt.show()
    plt.pause(0.01)
コード例 #3
0
""""
名称:045 体感灯光
硬件: 童芯派
功能介绍:实现led灯跟随童芯派姿态的变化而改变位置。

难度:⭐⭐⭐

支持的模式:上传、在线都支持

使用到的API及功能解读:

"""
# ---------程序分割线----------------程序分割线----------------程序分割线----------

import cyberpi
import time
a = 0

cyberpi.led.on('k k b k k')

while True:
    a = cyberpi.get_roll()
    time.sleep(0.2)
    if cyberpi.get_roll() - a > 36:
        cyberpi.led.move(step=1)
    if cyberpi.get_roll() - a < -36:
        cyberpi.led.move(step=-1)