当前位置: 首页>>代码示例>>Python>>正文


Python SenseHat.set_pixels方法代码示例

本文整理汇总了Python中sense_hat.SenseHat.set_pixels方法的典型用法代码示例。如果您正苦于以下问题:Python SenseHat.set_pixels方法的具体用法?Python SenseHat.set_pixels怎么用?Python SenseHat.set_pixels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sense_hat.SenseHat的用法示例。


在下文中一共展示了SenseHat.set_pixels方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
class RunTime:
    def __init__(self):
        self.apps = []
        self.apps.append(Clock())
        self.sense = SenseHat()

    def start(self):
        pygame.init()
        pygame.display.set_mode((640, 480))
        running = True
        icon = self.apps[0].get_icon()
        self.display_icon(icon)
        """
		while running:
			for event in pygame.event.get():
				if event.type == QUIT:
					running = False
				else:
					if event.key == K_RIGHT:
						self.sense.clear()
					elif event.key == K_LEFT:
						self.display_icon(icon)
					else:
						running = False
		"""

    def display_icon(self, icon):
        e = [0, 0, 0]
        padded_icon = []
        for i in range(0, len(icon)):
            padded_icon.append(e)
            padded_icon.extend(icon[i])
            padded_icon.append(e)
        padded_icon.extend([e, e, e, e, e, e, e, e, e, e, e, e, e, e, e, e])
        self.sense.set_pixels(padded_icon)
开发者ID:yjlo123,项目名称:runtime,代码行数:37,代码来源:RunTime.py

示例2: main

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
def main():
    # Initialization stuff
    sense = SenseHat()
    sense.low_light = True
    # Display a random pixel matrix
    pixelValues = [ [ random.randint( 0, 255 ) for j in range( 3 ) ] for i in range( 64 ) ]
    sense.set_pixels( pixelValues )
    time.sleep( 3 )
    # Create a colour 'beat'
    for i in range( 3 ):
        sense.clear( 255, 0, 0 )
        time.sleep ( 0.333 )
        sense.clear( 0, 255, 0 )
        time.sleep ( 0.333 )
        sense.clear( 0, 0, 255 )
        time.sleep ( 0.333 )
    # Toy around with text display
    message = "Einfach Mensch..."
    sense.show_message( message, 0.05 )
    rotation = 0
    for letter in message:
        sense.set_rotation( rotation, False )
        rotation += 90
        if rotation == 270:
            rotation = 0
        sense.show_letter( letter )
        time.sleep( 0.24 )
    sense.clear()
开发者ID:markuspg,项目名称:SenseHatStuff,代码行数:30,代码来源:randomPixels.py

示例3: new_game

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
        def new_game():
            global sense, a, b, r, t, m, w, k, y, x, h
            print("new_game ")
    
            #Sense hat reset
            sense.stick.direction_up = None
            sense.stick.direction_down = None
            sense.stick.direction_right = None
            sense.stick.direction_left = None
            sense.stick.direction_middle = None
            
            sense = SenseHat()
            sense.set_rotation(180)
            sense.clear()

            #Sense hat reset func
            sense.set_pixels(imagemenu)
            r = randint(0,4)
            t = randint(0,7)
            m = randint(4,7)
            w = randint(0,7)
            k = randint(2,6)
            y = 0
            x = 0
            a, b = (3, 4)
            sense.stick.get_events()
开发者ID:Coding4Kids,项目名称:cidadeinteligente,代码行数:28,代码来源:FugaAosQuadrados.py

示例4: main

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
def main(frames=FRAMES):
    """Show the frames on the sense hat."""
    sense = SenseHat()

    for frame in frames:
        sense.set_pixels(frame)
        time.sleep(0.25)
开发者ID:zeth,项目名称:princess,代码行数:9,代码来源:sheshiller.py

示例5: tv

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
def tv():
    sense = SenseHat()
    sense.clear()
    pygame.init()
    pygame.display.set_mode((640, 480))
    state = "Off"
    done=True
    while done:
        for event in pygame.event.get():

            
            if event.type == KEYDOWN:
                if event.key == K_RETURN and state == "On":
                    sense.clear()
                    state = "Off"
                    done=False
                    
                elif event.key == K_RETURN and state == "Off":
                    sense.set_pixels(channel4)
                    state = "On"
                elif event.key == K_DOWN:
                    sense.set_pixels(volumedown)
                elif event.key == K_UP:
                    sense.set_pixels(volumeup)
                elif event.key == K_LEFT:
                    sense.set_pixels(bw)
                elif event.key == K_RIGHT:
                    sense.set_pixels(fw)              
    pygame.quit()
开发者ID:Coding4Kids,项目名称:cidadeinteligente,代码行数:31,代码来源:smarthouse.py

示例6: __init__

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
class Screen:
    def __init__(self):
        self.sense = SenseHat()
        self.general_level = 0
        self.wait_time = 4
        self.cur_time = 0
        self.clear()
        self.balance = 0

    def clear(self):
        for i in range(SIZE):
            for j in range(SIZE):
                self.sense.set_pixel(i, j, BLACK)

    def clear_col(self, x):
        for i in range(0, 7):
            self.sense.set_pixel(x, i, BLACK)

    def plot_bar(self, x, height, colors=None):
        if colors is None:
            colors = BAR_COLORS
        self.clear_col(x)
        for i in range(height):
            self.sense.set_pixel(x, 7 - i, colors[7 - i])

    def plot_balance(self):
        for i in range(SIZE):
            self.plot_bar(i, max(1, self.general_level), BAR_COLORS)

    def show_amount(self):
        self.show_message(str(self.balance), color=list(BAR_COLORS[min(7, 8 - self.general_level)]))

    def show_message(self, message, speed=0.1, color=[255, 255, 255]):
        self.sense.show_message(message, speed, color)
        self.plot_balance()

    """ Parses an input in the form:
        balance percentage """

    def parse_input(self, line):
        self.cur_time = 0
        # Split balance and percentage.
        [self.balance, percent] = [float(x) for x in line.split()]
        self.general_level = int(round(min(max(0, percent), 100) / 100.0 * SIZE))
        self.draw_check()

    def draw_check(self):
        types = [BLACK, GREEN]
        pixels = [types[CHECK[i / SIZE][i % SIZE]] for i in range(SIZE * SIZE)]
        self.sense.set_pixels(pixels)

    def no_text(self):
        self.cur_time += SLEEP_TIME
        if self.cur_time > self.wait_time:
            self.cur_time = 0
            self.show_amount()
开发者ID:albertnez,项目名称:pep,代码行数:58,代码来源:screen.py

示例7: monitor_pass

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
def monitor_pass(pass_details):
    sense = SenseHat()
    sense.clear()

    p = pass_details
    
    t0 = p.StartTime
    t1 = p.HighTime
    t2 = p.EndTime

    pixels = [C.K] * 64

    nx, ny = 0, 0
    while True:
        time.sleep(0.1)
        t = datetime.utcnow()
        if t >= t0: break

        pixels[8 * ny + nx] = C.K
        nx, ny = border(Azimuth.from_string('N'))
        pixels[8 * ny + nx] = C.B

        sense.set_pixels(pixels)

    while True:
        time.sleep(0.1)
        t = datetime.utcnow()
        if t > t2: break

        if t < t1:
            x = (t - t0).total_seconds() / (t1 - t0).total_seconds()
            a = x * p.HighAzimuth + (1 - x) * p.StartAzimuth
            if a > 180:
                a = a - 360
        else:
            x = (t2 - t).total_seconds() / (t2 - t1).total_seconds()
            a = x * p.HighAzimuth + (1 - x) * p.EndAzimuth
            if a > 180:
                a = a - 360

        #print('{0:0.3f} {1:0.3f}'.format(x, distinv(x)))
        #pixels = spot(x, distinv)
        #pixels = spiral(x, ramp)
        pixels = spot(x, Tween.distinv)

        nx, ny = border(Azimuth.from_string('N'))
        pixels[8 * ny + nx] = C.B

        px, py = border(a)
        pixels[8 * py + px] = C.R

        sense.set_pixels(pixels)

    sense.clear()
开发者ID:svenzin,项目名称:iss-py,代码行数:56,代码来源:pass.py

示例8: __init__

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
class _SenseHat:
    def __init__(self, board_object, colour=""):
        self.board = board_object
        self.colour = colour
        self.sense = SenseHat()

    def magnetometer_on(self):
        self.sense.set_imu_config(True, False, False)  # gyroscope only

    @property
    def temp_c(self):
        return (self.sense.get_temperature_from_humidity() +
                self.sense.get_temperature_from_pressure())/2

    @property
    def pressure(self):
        return self.sense.pressure

    @property
    def humidity(self):
        return self.sense.humidity

    def led_all(self, colour):
        lcd = []
        for i in range(0, 64):
            lcd.append(colour)
        self.sense.set_pixels(lcd)

    def led_1(self, colour):
        self.sense.set_pixel(0, 0, colour)
        self.sense.set_pixel(0, 1, colour)
        self.sense.set_pixel(1, 0, colour)
        self.sense.set_pixel(1, 1, colour)

    def led_2(self, colour):
        self.sense.set_pixel(2, 2, colour)
        self.sense.set_pixel(2, 3, colour)
        self.sense.set_pixel(3, 2, colour)
        self.sense.set_pixel(3, 3, colour)

    def led_3(self, colour):
        self.sense.set_pixel(4, 4, colour)
        self.sense.set_pixel(4, 5, colour)
        self.sense.set_pixel(5, 4, colour)
        self.sense.set_pixel(5, 5, colour)

    def led_4(self, colour):
        self.sense.set_pixel(6, 6, colour)
        self.sense.set_pixel(6, 7, colour)
        self.sense.set_pixel(7, 6, colour)
        self.sense.set_pixel(7, 7, colour)

    def clear(self):
        self.sense.clear()
开发者ID:LozMarshall,项目名称:home_auto_year_one,代码行数:56,代码来源:sensehat.py

示例9: music

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
def music():
    sense = SenseHat()
    sense.clear()
    pygame.init()
    pygame.display.set_mode((640, 480))
    mixer.init()
    #music
    path = "/home/pi/Desktop/Smart House/Music"
    mfiles = [f for f in os.listdir(path) if f.endswith('.mp3')]
    abc = 2
    state = "Off"
    running = True
    while running:
        for event in pygame.event.get():
            if event.type == KEYDOWN:
                if event.key == K_RETURN and state == "On":
                    sense.clear()
                    state = "Off"
                    mixer.music.stop()
                    running = False
                elif event.key == K_RETURN and state == "Off":
                    sense.set_pixels(song2)
                    state = "On"
                    
                    mixer.music.load(path + '/' + mfiles[abc])
                    mixer.music.play()
                elif event.key == K_DOWN:
                     sense.set_pixels(volumedown)
                elif event.key == K_UP:
                     sense.set_pixels(volumeup)
                elif event.key == K_LEFT:
                    sense.set_pixels(song2) 
                    if abc>0:
                        abc = abc-1
                    else:
                        abc= len(mfiles)-1
                    mixer.music.load(path + '/' + mfiles[abc])
                    mixer.music.play()
                                             
                elif event.key == K_RIGHT:
                    sense.set_pixels(song2)
                    if abc<(len(mfiles)-1):
                         abc = abc+1
                    else:
                         abc = 0
                    mixer.music.load(path + '/' + mfiles[abc])
                    mixer.music.play()
                    
            
    pygame.quit()
开发者ID:Coding4Kids,项目名称:cidadeinteligente,代码行数:52,代码来源:smarthouse.py

示例10: draw_bluetooth

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
def draw_bluetooth():
    B = [0, 0, 255]  # Blue
    O = [255, 255, 255]  # White
    sense = SenseHat()
    bluetooth_logo = [
        O, O, O, O, O, O, O, O,
        O, O, O, B, O, O, O, O,
        O, O, O, B, B, O, O, O,
        O, B, O, B, O, B, O, O,
        O, O, B, B, B, O, O, O,
        O, B, O, B, O, B, O, O,
        O, O, O, B, B, O, O, O,
        O, O, O, B, O, O, O, O
    ]
    sense.set_pixels(bluetooth_logo)
开发者ID:allencho0223,项目名称:piot_a1,代码行数:17,代码来源:bluetooth_register.py

示例11: main

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
def main():
    sense = SenseHat()
    sense.low_light = True
    print( "<---- SinusGraph ---->\n" )
    pixelStatuses = [ [ 0, 0, 0 ] for i in range( 64 ) ]
    for i in range( 150 ):
        assert len( pixelStatuses ) == 64
        del pixelStatuses[ : 8 ]
        pixelStatuses.extend( [ [ 0, 0, 0 ] for i in range( 8 ) ] )
        pixelStatuses[ 60 + round( cos( i / 1.5 ) * 3 ) ] = [ 0, 255, 0 ]
        pixelStatuses[ 60 + round( sin( i / 2 ) * 3 ) ] = [ 255, 255, 255 ]
        sense.set_pixels( pixelStatuses )
        pixelStatuses = sense.get_pixels()
        print( pixelStatuses )
        sleep( 0.096 )
    sense.clear()
开发者ID:markuspg,项目名称:SenseHatStuff,代码行数:18,代码来源:sinusGraph.py

示例12: hello_world

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
def hello_world():
    sense = SenseHat()
    X = [255, 0, 0]  # Red
    O = [255, 255, 255]  # White

    question_mark = [
    O, O, O, X, X, O, O, O,
    O, O, X, O, O, X, O, O,
    O, O, O, O, O, X, O, O,
    O, O, O, O, X, O, O, O,
    O, O, O, X, O, O, O, O,
    O, O, O, X, O, O, O, O,
    O, O, O, O, O, O, O, O,
    O, O, O, X, O, O, O, O
    ]

    sense.set_pixels(question_mark)
    return 'Hello World!'
开发者ID:kaitokidi,项目名称:PenguinsOFCfinnappsparty,代码行数:20,代码来源:finapps_api.py

示例13: Main

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
def Main():
  '''Wrapper.'''

  #
  # Collect data.
  #
  data = FetchCitiBikeData()
  station = ExtractStationData(data=data,id=445)

  #
  # Generate pixels.
  #
  pixels = GeneratePixels(station['data']['availableBikes'])

  #
  # Send to SenseHAT.
  #
  sense = SenseHat()
  sense.set_pixels(pixels)
开发者ID:rolltime,项目名称:rolltime-raspberry-pi,代码行数:21,代码来源:server.py

示例14: display2

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
	def display2(self):
		# Levels of dist
		d1 = self.int2rgb(self.siglevel_dt(-20,0))
		d2 = self.int2rgb(self.siglevel_dt(-40,-21))
		d3 = self.int2rgb(self.siglevel_dt(-60,-41))
		d4 = self.int2rgb(self.siglevel_dt(-100,-61))
		
		#print self.siglevel_dt(-50,0)	

		sense = SenseHat()
		pixels = [
		d4,d4,d4,d4,d4,d4,d4,d4,
		d4,d3,d3,d3,d3,d3,d3,d4,
		d4,d3,d2,d2,d2,d2,d3,d4,
		d4,d3,d2,d1,d1,d2,d3,d4,
		d4,d3,d2,d1,d1,d2,d3,d4,
		d4,d3,d2,d2,d2,d2,d3,d4,
		d4,d3,d3,d3,d3,d3,d3,d4,
		d4,d4,d4,d4,d4,d4,d4,d4]
		
		sense.set_pixels(pixels)
开发者ID:savnik,项目名称:smart_city_sensor,代码行数:23,代码来源:mac_int.py

示例15: menu

# 需要导入模块: from sense_hat import SenseHat [as 别名]
# 或者: from sense_hat.SenseHat import set_pixels [as 别名]
        def menu():
            global sense, time1, time2, r, t, m, w, k, a, b, elapsed
            sense = SenseHat()
            
            sense.set_rotation(180)
            sense.clear()
            sense.set_pixels(imagemenu)
            
            sense.stick.get_events()
            while True:
                print (" new game1",a," ",b)
                y1 = sense.get_accelerometer_raw()['y']
                y1 = round(y1, 0)

                if y1 == -1:
                    sense.show_message("Highscore '%s'"% (h))
                    sense.set_pixels(imagemenu)
                for event in sense.stick.get_events():
                    if event.action == "pressed" and event.direction == "middle":
                        elapsed = timedelta(seconds=0)
                        sense.set_rotation(180)
                        sense.stick.direction_up = move_up
                        sense.stick.direction_down = move_down
                        sense.stick.direction_right = move_right
                        sense.stick.direction_left = move_left
                        x=0
                        y=0
                        time1 = datetime.now()
                        print(elapsed, " elapsed and e ", e)
                        while elapsed < e:
                            sense.clear()
                            draw_player()
                            test = draw_enemy(x, y)
                            print("menu nivel1 ",test)
                            if test == 1:
                                new_game()
                                break
                            sleep(0.25)
                            y = y+1
                            if y > 7:
                                r = randint(0,7)
                                t = randint(0,7)
                                m = randint(0,7)
                                y = 0
                            x = x+1
                            if x > 7:
                                w = randint(0,7)
                                k = randint(0,7)
                                x = 0
                        if elapsed > e:
                                sense.show_message("Next level", scroll_speed=0.05)
                                sense.set_pixels(imagesmile)
                                sleep(1)
                                level_2(x,y)
                                new_game()
                                break
                    if event.action == "pressed" and (event.direction == "up" or event.direction == "down" or event.direction == "left" or event.direction == "right"):
                        return
开发者ID:Coding4Kids,项目名称:cidadeinteligente,代码行数:60,代码来源:FugaAosQuadrados.py


注:本文中的sense_hat.SenseHat.set_pixels方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。