if LEFT in clicks: if not use2: x1 -= 1 else: x2 -= 1 if RIGHT in clicks: if not use2: x1 += 1 else: x2 += 1 if DOWN in clicks: if not use2: y1 -= 1 else: y2 -= 1 if UP in clicks: if not use2: y1 += 1 else: y2 += 1 if SHOOT in clicks: use2 = not use2 led.erase() color1 = 3 if not use2 else 1 color2 = 3 if use2 else 1 led.point(x1, y1, color=color1) led.point(x2, y2, color=color2) led.show() time.sleep(POLL_PERIOD)
# import time from rstem import led from rstem import accel from rstem import gpio POLL_PERIOD = 0.010 LEFT = 3 DOWN = 4 UP = 14 RIGHT = 15 for g in [LEFT, DOWN, UP, RIGHT]: gpio.configure(g, gpio.INPUT) x, y = 5, 5 while True: clicks = gpio.was_clicked() if LEFT in clicks: x -= 1 if RIGHT in clicks: x += 1 if DOWN in clicks: y -= 1 if UP in clicks: y += 1 led.erase() led.point(x, y) led.show() time.sleep(POLL_PERIOD)
class AddableTuple(tuple): def __add__(self, a): return self.__class__([sum(t) for t in zip(self, a)]) change = { LEFT : AddableTuple((-1,0)), RIGHT : AddableTuple((+1,0)), UP : AddableTuple((0,+1)), DOWN : AddableTuple((0,-1)), } dots = [AddableTuple((0,0)) for i in range(num_dots)] current_dot = 0 while True: clicks = gpio.was_clicked() for c in clicks: if c in [LEFT, RIGHT, UP, DOWN]: dots[current_dot] += change[c] if c == SHOOT: current_dot = (current_dot + 1) % num_dots led.erase() for i, d in enumerate(dots): if i == current_dot: continue led.point(dots[i], color=1) led.point(dots[current_dot], color=3) led.show() time.sleep(POLL_PERIOD)
clicks = gpio.was_clicked() if LEFT in clicks: if not use2: x1 -= 1 else: x2 -= 1 if RIGHT in clicks: if not use2: x1 += 1 else: x2 += 1 if DOWN in clicks: if not use2: y1 -= 1 else: y2 -= 1 if UP in clicks: if not use2: y1 += 1 else: y2 += 1 if SHOOT in clicks: use2 = not use2 led.erase() color1 = 3 if not use2 else 1 color2 = 3 if use2 else 1 led.point(x1, y1, color=color1) led.point(x2, y2, color=color2) led.show() time.sleep(POLL_PERIOD)
class AddableTuple(tuple): def __add__(self, a): return self.__class__([sum(t) for t in zip(self, a)]) change = { LEFT: AddableTuple((-1, 0)), RIGHT: AddableTuple((+1, 0)), UP: AddableTuple((0, +1)), DOWN: AddableTuple((0, -1)), } dots = [AddableTuple((0, 0)) for i in range(num_dots)] current_dot = 0 while True: clicks = gpio.was_clicked() for c in clicks: if c in [LEFT, RIGHT, UP, DOWN]: dots[current_dot] += change[c] if c == SHOOT: current_dot = (current_dot + 1) % num_dots led.erase() for i, d in enumerate(dots): if i == current_dot: continue led.point(dots[i], color=1) led.point(dots[current_dot], color=3) led.show() time.sleep(POLL_PERIOD)
# the terms of the GNU General Public License version 2 as published by the # Free Software Foundation. See the file COPYING included with this software # for the full license. # import time from rstem import led # Create a list of points, that are all the points of the marquee border, in # order. max_width = led.width() - 1 max_height = led.height() - 1 top = [(x, max_height) for x in range(max_width)] right = [(max_width, max_height-y) for y in range(max_height)] bottom = [(max_width-x, 0) for x in range(max_width)] left = [(0, y) for y in range(max_height)] marquee = top + right + bottom + left percent_on = 30 while True: # For each point in the marquee, up to the defined percent_on, draw the # point led.erase() for i, point in enumerate(marquee): if i % len(marquee) < (percent_on/100.0) * len(marquee): led.point(point) led.show() time.sleep(0.1); # Rotate all the points in the marquee marquee = marquee[1:] + [marquee[0]]
def draw(self): led.point(int(self.x), int(self.y))
# Copyright (c) 2014, Scott Silver Labs, LLC. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # import time from rstem import led from rstem import accel xbase, ybase = accel.get_data() x, y = (led.width()/2, led.height()/2) while True: xaccel, yaccel = accel.get_data() xchg = (xaccel - xbase)/20.0 ychg = (yaccel - ybase)/20.0 x, y = led.bound(int(x + xchg), int(y + ychg)) led.erase() led.point(x, y) led.show() time.sleep(0.1);