Beispiel #1
0
def getstravabargraph():
    global totaldistance
    totaldistance = 0
    activitiesthisyear = client.get_activities(
        after=mondaypst, limit=500)  # Download all activities this year

    for activity in activitiesthisyear:
        totaldistance += float(stravalib.unithelper.miles(
            activity.distance))  #add up the total distance

    limit = 0
    bargraph = []
    #Get the most recent 5 activities to draw the bar chart
    for activity in sorted(activitiesthisyear, key=sortby, reverse=True):
        bargraph.append(
            int(
                math.ceil(
                    float(stravalib.unithelper.miles(activity.distance)) /
                    km_per_pixel)))
        limit += 1
        if limit == 5:  #only get most recent 5 activities (1 per row of pixels)
            break

    bargraph.reverse()
    return bargraph

    # def drawgraph(values):
    scrollphat.clear_buffer()
    for row, value in enumerate(values):
        for col in range(0, 11):
            if value <= col:
                scrollphat.set_pixel(col, row, False)
            else:
                scrollphat.set_pixel(col, row, True)
    scrollphat.update()
Beispiel #2
0
def on_sensor_data(channel, data):
    print(channel, data)
    val = float(r.get_key(data+".temp"))
    print(str(val))

    scrollphat.write_string( str(round(val))[:2] )
    scrollphat.update()
Beispiel #3
0
def set_checker(offset):
    n = offset
    for y in range(5):
        for x in range(11):
            scrollphat.set_pixel(x,y,n % 2 == 0)
            n += 1
    scrollphat.update()
Beispiel #4
0
    def scroll_message(self):

        time_count_par_sec = 1 / self.lotate_time_sec
        time_count_limit = time_count_par_sec * self.update_time_sec
        time_count = time_count_limit
        while True:
            try:
                if time_count >= time_count_limit:
                    print("")
                    print(" --- Check... ---")
                    time_count = 0
                    if self.get_weather_days(self.check_days):
                        print(" --- Update... ---")
                        self.add_optional_signal_output("start")
                        self.add_get_weather_time_output()
                        self.add_optional_signal_output("end")
                        self.get_weather_info()
                        scrollphat.write_string(self.output)
                        scrollphat.update()
                    else:
                        print(" --- No Update... ---")
                        print("   Updated: " + self.pub_date)
                        print(" --------------------")
                scrollphat.scroll()
                scrollphat.update()
                time.sleep(self.lotate_time_sec)
                time_count += 1

            except KeyboardInterrupt:
                print("\nInterrupted Ctrl + C !!\n")
                return
    def display(self, amt):
        val = 0
        if(amt != None):
            val = int(amt)
            if(val > self.MAX):
                val = self.MAX
                self.flash(val)
                return

        if(val == self.last):
            return

        if(self.last > val):
            scrollphat.clear()

        self.last = val

        y = 0
        x = 0
        while(val > 0):
            scrollphat.set_pixel(x, y, True)
            scrollphat.update()
            x = x + 1
            if(x == 10):
                y = y + 1
                x = 0
            val = val -1
Beispiel #6
0
    def scrollInSteps(self, stepNumber):
        '''Sets the columns positions from scrolling in from stepNumber'''

        if self.args.verbose:
            print('Running SpaceInvader.scrollInSteps, stepNumber: {}'.format(
                stepNumber))

        # Arm Down
        if stepNumber == 1:
            self.armDownColumn(0, 10)

        # Arm Up
        elif stepNumber == 2:
            for i in range(0, 2):
                self.armUpColumn(i, i + 9)

        # Arm Down
        elif stepNumber == 3:
            for i in range(0, 3):
                self.armDownColumn(i, i + 8)

        # Arm Up
        if stepNumber == 4:
            for i in range(0, 4):
                self.armUpColumn(i, i + 7)

        # Arm Down
        elif stepNumber == 5:
            for i in range(0, 5):
                self.armDownColumn(i, i + 6)

        # Arm Up
        if stepNumber == 6:
            for i in range(0, 6):
                self.armUpColumn(i, i + 5)

        # Arm Down
        elif stepNumber == 7:
            for i in range(0, 7):
                self.armDownColumn(i, i + 4)

        # Arm Up
        if stepNumber == 8:
            for i in range(0, 8):
                self.armUpColumn(i, i + 3)

        # Arm Down
        elif stepNumber == 9:
            for i in range(0, 9):
                self.armDownColumn(i, i + 2)

        # Arm Up
        elif stepNumber == 10:
            for i in range(0, 10):
                self.armUpColumn(i, i + 1)

        scrollphat.update()
        time.sleep(self.args.pause_scroll)
        scrollphat.clear()
Beispiel #7
0
 def print_scroll(self):
     scrollphat.clear()
     for x, col in enumerate(self.field.buffer):
         for y, pixel in enumerate(col):
             scrollphat.set_pixel(x, y, pixel)
     scrollphat.set_pixel(self.ai.player.x, self.ai.player.y, 1)
     if SCREEN_TYPE == "SCROLL": scrollphat.update()
     if SCREEN_TYPE == "SCROLLHD": scrollphat.show()
Beispiel #8
0
 def show(self):
     packed = np.packbits(np.pad((self.rawbuf[::-1, :, 0] & 0x80) > 0,
                                 ((3, 0), (0, 0)),
                                 mode='constant'),
                          axis=0)
     scrollphat.set_buffer(packed[0].tolist())
     scrollphat.update()
     super().show()
Beispiel #9
0
 def on_message(self, message):
     cmd = json.loads(message)
     #{u'raw': 1, u'turned_on': True, u'led': 1}
     if cmd['turned_on']:
         scrollphat.set_pixel(cmd['led'],cmd['raw'],1)
     else:
         scrollphat.set_pixel(cmd['led'],cmd['raw'],0)
     scrollphat.update()
Beispiel #10
0
    def bufferFall(self, buf):
        '''Sets the buffer for snow'''

        if self.verbose:
            print('Running Snow.bufferFall, buf: %s' % buf)

        scrollphat.set_buffer(buf)
        scrollphat.update()
        time.sleep(self.fallSpeed)
Beispiel #11
0
def displaySprite(sprite):
    """Display a simple sprite on the matrix.
    The sprite should be an array of 5 binary strings"""
    print("Displaying Sprite: %s"  % sprite)
    scrollphat.clear()
    for rowNum, row in enumerate(sprite):
        for colNum, cell in enumerate(row):
            scrollphat.set_pixel(colNum, rowNum, int(cell))
    scrollphat.update()
Beispiel #12
0
 def set_checker(self, offset):
     scrollphat.clear()
     n = offset
     for y in range(SCREEN_HEIGHT):
         for x in range(SCREEN_WIDTH):
             scrollphat.set_pixel(x, y, n % 2 == 0)
             n += 1
     if SCREEN_TYPE == "SCROLL": scrollphat.update()
     if SCREEN_TYPE == "SCROLLHD": scrollphat.show()
Beispiel #13
0
def scroll_life(delay):
    def count_neighbours(ibuf, i, j):
        tot=0
        for x,y in ((-1,-1), (-1,0), (-1,1),
                    ( 0,-1)         , (0,1),
                    (+1,-1), (+1,0), (+1,1)):
            ix=(i+x)%11
            jy=(j+y)%5
            tot+=ibuf[ix][jy]
        return tot
    
    def buffer(ibuf):
        return [ibuf2buf[tuple(v)] for v in ibuf]
    
    def rand_ibuf():
        return [[(random.random()>0.8)+0 for j in range(5)] for i in range(11)]
    
    def glider_ibuf():
        return [[0,0,0,0,0], 
                [0,0,0,0,0], 
                [0,0,0,0,0], 
                [0,0,1,0,0], 
                [0,1,0,0,0], 
                [0,1,1,1,0], 
                [0,0,0,0,0], 
                [0,0,0,0,0], 
                [0,0,0,0,0], 
                [0,0,0,0,0], 
                [0,0,0,0,0]]          

    ibuf=rand_ibuf()
    ibuf2buf={(i,j,k,l,m): (i<<0)+(j<<1)+(k<<2)+(l<<3)+(m<<4)
              for i in (0,1)
              for j in (0,1)
              for k in (0,1)
              for l in (0,1)
              for m in (0,1)}
    samecount=0
    while True:
        ibufbuf=copy.deepcopy(ibuf)
        for i in range(11):
            for j in range(5):
                c=count_neighbours(ibufbuf, i, j)
                if ibuf[i][j]:
                    if c in (0,1,4,5,6,7):
                        ibuf[i][j]=0
                else:
                    if c in (3,):
                        ibuf[i][j]=1
        buf=buffer(ibuf)
        scrollphat.set_buffer(buf)
        scrollphat.update()
        time.sleep(delay)
        if ibufbuf==ibuf:
            samecount+=1
        if samecount>20:
            ibuf=rand_ibuf()
Beispiel #14
0
def ledstage( stage ):

        pause_time = 0.03
        scrollphat.set_brightness(2)

        for y in range(5):
                for x in range(stage):
                        scrollphat.set_pixel(x,y,1)
                        scrollphat.update()
                        time.sleep(pause_time)
Beispiel #15
0
    def show(self):
        '''Displays the twitter logo'''

        if self.args.verbose:
            print('Running Twitter.show')

        self.setCentered()
        scrollphat.update()
        time.sleep(self.args.pause_show)
        scrollphat.clear()
    def __init__(self):
        MID_LEVEL = 10
        scrollphat.clear()
        scrollphat.update()
        scrollphat.set_brightness(MID_LEVEL)

        self.last = 0
        self.HEIGHT = 5
        self.WIDTH = 11
        self.MAX = (self.WIDTH) * (self.HEIGHT)
Beispiel #17
0
def ledstage(stage):

    pause_time = 0.03
    scrollphat.set_brightness(2)

    for y in range(5):
        for x in range(stage):
            scrollphat.set_pixel(x, y, 1)
            scrollphat.update()
            time.sleep(pause_time)
Beispiel #18
0
def scroll_message(output):
    scrollphat.write_string(output)
    scrollphat.update()

    while (True):
        try:
            scrollphat.scroll()
            scrollphat.update()
            time.sleep(0.2)
        except KeyboardInterrupt:
            return
Beispiel #19
0
    def scrollOutSteps(self, stepNumber):
        '''Sets the columns positions from scrolling out from stepNumber'''

        if self.args.verbose:
            print('Running SpaceInvader.scrollOutSteps, stepNumber: {}'.format(
                stepNumber))

        # Arm Up
        if stepNumber == 1:
            for i in range(1, 10):
                self.armUpColumn(i, i - 1)

        # Arm Down
        elif stepNumber == 2:
            for i in range(2, 10):
                self.armDownColumn(i, i - 2)

        # Arm Up
        elif stepNumber == 3:
            for i in range(3, 10):
                self.armUpColumn(i, i - 3)

        # Arm Down
        elif stepNumber == 4:
            for i in range(4, 10):
                self.armDownColumn(i, i - 4)

        # Arm Up
        elif stepNumber == 5:
            for i in range(5, 10):
                self.armUpColumn(i, i - 5)

        # Arm Down
        elif stepNumber == 6:
            for i in range(6, 10):
                self.armDownColumn(i, i - 6)

        # Arm Up
        elif stepNumber == 7:
            for i in range(7, 10):
                self.armUpColumn(i, i - 7)

        # Arm Down
        elif stepNumber == 8:
            for i in range(8, 10):
                self.armDownColumn(i, i - 8)

        # Arm Up
        elif stepNumber == 9:
            self.armUpColumn(9, 0)

        scrollphat.update()
        time.sleep(self.args.pause_scroll)
        scrollphat.clear()
def scroll_message(output):
    scrollphat.write_string(output)
    scrollphat.update()

    while(True):
        try:
            scrollphat.scroll()
            scrollphat.update()
            time.sleep(0.2)
        except KeyboardInterrupt:
            return
 def slow_fill(self, val, pause):
     y = 0
     x = 0
     while(val > 0):
         scrollphat.set_pixel(x, y, True)
         time.sleep(pause)
         scrollphat.update()
         x = x + 1
         if(x == 10):
             y = y + 1
             x = 0
         val = val -1
Beispiel #22
0
    def setPositionMiddleClosed(self):
        '''Sets of the pacman to be displayed at the middle position'''

        if self.args.verbose:
            print('Running Pacman.setPositionMiddleClosed')

        self.mouthClosedColumn(4, 7)
        self.mouthClosedColumn(3, 6)
        self.mouthClosedColumn(2, 5)
        self.mouthClosedColumn(1, 4)
        self.mouthClosedColumn(0, 3)
        scrollphat.update()
    def clear(fast=False):
        log_str('clear scroll')

        if not fast:
            for x in range(11):
                for y in range(5):
                    scrollphat.set_pixel(x, y, 0)
                    sleep(0.015)
                    scrollphat.update()

        scrollphat.clear_buffer()
        scrollphat.clear()
        scrollphat.update()
def clear(pause):
    # arrow body
    for x in range(11):
        scrollphat.set_pixel(x, 2, 0)

    # arrow tip part
    scrollphat.set_pixel(8, 0, 0)
    scrollphat.set_pixel(9, 1, 0)
    scrollphat.set_pixel(9, 3, 0)
    scrollphat.set_pixel(8, 4, 0)

    scrollphat.update()
    time.sleep(pause)
def paint(pause):
    # arrow body
    for x in range(11):
        scrollphat.set_pixel(x, 2, 1)

    # arrow tip part
    scrollphat.set_pixel(8, 0, 1)
    scrollphat.set_pixel(9, 1, 1)
    scrollphat.set_pixel(9, 3, 1)
    scrollphat.set_pixel(8, 4, 1)

    scrollphat.update()
    time.sleep(pause)
Beispiel #26
0
    def dance(self, position):
        '''Sets the tree to dance vertically from position'''

        if self.args.verbose:
            print('Running DisplayVertical.dance, position: %s' % position)
            print('Dancing for %s times' % self.args.dance_times)

        for i in range(0, self.args.dance_times):

            # Center
            self.setPositionCenter(position)
            scrollphat.update()
            time.sleep(args.pause_dance)
            scrollphat.clear()

            # Left
            self.setPositionLeft(position)
            scrollphat.update()
            time.sleep(args.pause_dance)
            scrollphat.clear()

            # Center
            self.setPositionCenter(position)
            scrollphat.update()
            time.sleep(args.pause_dance)
            scrollphat.clear()

            # Right
            self.setPositionRight(position)
            scrollphat.update()
            time.sleep(args.pause_dance)
            scrollphat.clear()
Beispiel #27
0
    def scrollRightLeftInSteps(self, stepNumber):
        '''Sets the columns positions for right to left scrolling in from stepNumber'''

        if self.args.verbose:
            print('Running Twitter.scrollRightLeftInSteps, stepNumber: %s' %
                  stepNumber)

        if stepNumber == 1:
            self.columnPosition(10, 0)

        elif stepNumber == 2:
            for i in range(9, 11):
                self.columnPosition(i, i - 9)

        elif stepNumber == 3:
            for i in range(8, 11):
                self.columnPosition(i, i - 8)

        elif stepNumber == 4:
            for i in range(7, 11):
                self.columnPosition(i, i - 7)

        elif stepNumber == 5:
            for i in range(6, 11):
                self.columnPosition(i, i - 6)

        elif stepNumber == 6:
            for i in range(5, 11):
                self.columnPosition(i, i - 5)

        elif stepNumber == 7:
            for i in range(4, 11):
                self.columnPosition(i, i - 4)

        elif stepNumber == 8:
            for i in range(3, 11):
                self.columnPosition(i, i - 3)

        elif stepNumber == 9:
            for i in range(2, 11):
                self.columnPosition(i, i - 2)

        elif stepNumber == 10:
            for i in range(1, 11):
                self.columnPosition(i, i - 1)

        scrollphat.update()
        time.sleep(self.args.pause_scroll)
        scrollphat.clear()
Beispiel #28
0
    def scrollRightLeftOutSteps(self, stepNumber):
        '''Sets the columns positions for right to left scrolling out from stepNumber'''

        if self.args.verbose:
            print('Running Twitter.scrollRightLeftOutSteps, stepNumber: %s' %
                  stepNumber)

        if stepNumber == 1:
            for i in range(0, 10):
                self.columnPosition(i, i + 1)

        elif stepNumber == 2:
            for i in range(0, 9):
                self.columnPosition(i, i + 2)

        elif stepNumber == 3:
            for i in range(0, 8):
                self.columnPosition(i, i + 3)

        elif stepNumber == 4:
            for i in range(0, 7):
                self.columnPosition(i, i + 4)

        elif stepNumber == 5:
            for i in range(0, 6):
                self.columnPosition(i, i + 5)

        elif stepNumber == 6:
            for i in range(0, 5):
                self.columnPosition(i, i + 6)

        elif stepNumber == 7:
            for i in range(0, 4):
                self.columnPosition(i, i + 7)

        elif stepNumber == 8:
            for i in range(0, 3):
                self.columnPosition(i, i + 8)

        elif stepNumber == 9:
            for i in range(0, 2):
                self.columnPosition(i, i + 9)

        elif stepNumber == 10:
            self.columnPosition(0, 10)

        scrollphat.update()
        time.sleep(self.args.pause_scroll)
        scrollphat.clear()
Beispiel #29
0
    def setPositionMiddle(self):
        '''Displays the centered tree in the middle of the scroll-pHAT'''

        if self.args.verbose:
            print('Running DisplayHorizontal.setPositionMiddle')

        self.columnCenterPosition(0, 2)
        self.columnCenterPosition(1, 3)
        self.columnCenterPosition(2, 4)
        self.columnCenterPosition(3, 5)
        self.columnCenterPosition(4, 6)
        self.columnCenterPosition(5, 7)
        self.columnCenterPosition(6, 8)

        scrollphat.update()
Beispiel #30
0
    def on_message(self, message):
#        print 'message received %s' % message
        action = True
        rawled=int(message)
        if rawled < 0:
            rawled=rawled*-1
            action= False

        led= rawled-1
        a= led % 11
        b= led // 11
        import scrollphat
#        scrollphat.clear()
        scrollphat.set_pixel(a,b,action)
        scrollphat.update()
Beispiel #31
0
    def setPositionMiddle(self):
        '''Sets the tree at the verticall middle position'''

        if self.args.verbose:
            print('Running DisplayVertical.setPositionMiddle')

        self.columnCenterPosition(0, 2)
        self.columnCenterPosition(1, 3)
        self.columnCenterPosition(2, 4)
        self.columnCenterPosition(3, 5)
        self.columnCenterPosition(4, 6)
        self.columnCenterPosition(5, 7)
        self.columnCenterPosition(6, 8)

        scrollphat.update()
Beispiel #32
0
    def scrollRightLeftOutSteps(self, stepNumber):
        '''Sets the columns positions from right to left scrolling-out from stepNumber'''

        if self.args.verbose:
            print(
                'Running Pacman.scrollLeftRightInSteps, stepNumber: {}'.format(
                    stepNumber))

        # Open
        if stepNumber == 1:
            for i in range(0, 5):
                self.mouthOpenColumn(i, 6 - i)

        # Closed
        elif stepNumber == 2:
            for i in range(0, 5):
                self.mouthClosedColumn(i, 5 - i)

        # Open
        elif stepNumber == 3:
            for i in range(0, 5):
                self.mouthOpenColumn(i, 4 - i)

        # Closed
        elif stepNumber == 4:
            for i in range(0, 4):
                self.mouthClosedColumn(i, 3 - i)

        # Open
        elif stepNumber == 5:
            for i in range(0, 3):
                self.mouthOpenColumn(i, 2 - i)

        # Closed
        elif stepNumber == 6:
            for i in range(0, 2):
                self.mouthClosedColumn(i, 1 - i)

        # Open
        elif stepNumber == 7:
            self.mouthOpenColumn(0, 0)

        scrollphat.update()
        time.sleep(self.args.pause_scroll)
        scrollphat.clear()
Beispiel #33
0
    def scrollRightLeftInSteps(self, stepNumber):
        '''Sets the columns positions from right to left scrolling-in from stepNumber'''

        if self.args.verbose:
            print(
                'Running Pacman.scrollLeftRightInSteps, stepNumber: {}'.format(
                    stepNumber))

        # Open
        if stepNumber == 1:
            self.mouthOpenColumn(4, 10)

        # Closed
        elif stepNumber == 2:
            for i in range(3, 5):
                self.mouthClosedColumn(i, 13 - i)

        # Open
        elif stepNumber == 3:
            for i in range(2, 5):
                self.mouthOpenColumn(i, 12 - i)

        # Closed
        elif stepNumber == 4:
            for i in range(1, 5):
                self.mouthClosedColumn(i, 11 - i)

        # Open
        elif stepNumber == 5:
            for i in range(0, 5):
                self.mouthOpenColumn(i, 10 - i)

        # Closed
        elif stepNumber == 6:
            for i in range(0, 5):
                self.mouthClosedColumn(i, 9 - i)

        # Open
        elif stepNumber == 7:
            for i in range(0, 5):
                self.mouthOpenColumn(i, 8 - i)

        scrollphat.update()
        time.sleep(self.args.pause_scroll)
        scrollphat.clear()
    def scrollphat_output(days, hours, minutes, seconds, total):
        global start_seconds
        start_seconds = start_seconds or total

        bar = int(5 * (float(total) / start_seconds))

        scrollphat.clear_buffer()
        s = str(seconds)
        indent = 2
        if len(s) == 1:
            indent = 4

        scrollphat.write_string(s, indent)

        for y in range(bar):
            scrollphat.set_pixel(0, y, 1)

        scrollphat.update()
Beispiel #35
0
    def scrollLeftRightOutSteps(self, stepNumber):
        '''Sets the columns positions from left to right scrolling-out from stepNumber'''

        if self.args.verbose:
            print('Running Pacman.scrollLeftRightOutSteps, stepNumber: %s' %
                  stepNumber)

        # Open
        if stepNumber == 1:
            for i in range(0, 5):
                self.mouthOpenColumn(i, i + 4)

        # Closed
        elif stepNumber == 2:
            for i in range(0, 5):
                self.mouthClosedColumn(i, i + 5)

        # Open
        elif stepNumber == 3:
            for i in range(0, 5):
                self.mouthOpenColumn(i, i + 6)

        # Closed
        elif stepNumber == 4:
            for i in range(0, 4):
                self.mouthClosedColumn(i, i + 7)

        # Open
        elif stepNumber == 5:
            for i in range(0, 3):
                self.mouthOpenColumn(i, i + 8)

        # Closed
        elif stepNumber == 6:
            for i in range(0, 2):
                self.mouthClosedColumn(i, i + 9)

        # Open
        elif stepNumber == 7:
            self.mouthOpenColumn(0, 10)

        scrollphat.update()
        time.sleep(self.args.pause_scroll)
        scrollphat.clear()
Beispiel #36
0
    def scrollLeftRightInSteps(self, stepNumber):
        '''Sets the columns positions from left to right scrolling-in from stepNumber'''

        if self.args.verbose:
            print('Running Pacman.scrollLeftRightInSteps, stepNumber: %s' %
                  stepNumber)

        # Open
        if stepNumber == 1:
            self.mouthOpenColumn(4, 0)

        # Closed
        elif stepNumber == 2:
            for i in range(3, 5):
                self.mouthClosedColumn(i, i - 3)

        # Open
        elif stepNumber == 3:
            for i in range(2, 5):
                self.mouthOpenColumn(i, i - 2)

        # Closed
        elif stepNumber == 4:
            for i in range(1, 5):
                self.mouthClosedColumn(i, i - 1)

        # Open
        elif stepNumber == 5:
            for i in range(0, 5):
                self.mouthOpenColumn(i, i)

        # Closed
        elif stepNumber == 6:
            for i in range(0, 5):
                self.mouthClosedColumn(i, i + 1)

        # Open
        elif stepNumber == 7:
            for i in range(0, 5):
                self.mouthOpenColumn(i, i + 2)

        scrollphat.update()
        time.sleep(self.args.pause_scroll)
        scrollphat.clear()
Beispiel #37
0
def mainprog():
    "Display current time with pixels on the Scroll pHAT."
    global disp

    t = time.strftime(f, time.localtime())
    h1, h2, m1, m2 = [int(x) for x in t]
    disp = [[2, 4, 4, 4, 1, 6, 6, 1, 8, 8, 8] for y in range(3)]
    tog(0, 1, h1, 3)
    tog(1, 4, h2, 5)
    tog(5, 7, m1, 7)
    tog(8, 11, m2, 9)
    for x in range(11):
        for y in range(3):
            r, g, b = colors[disp[y][x]]
            if (r + g + b > 0):
                scrollphat.set_pixel(x, y + 1, 1)
            else:
                scrollphat.set_pixel(x, y + 1, 0)
    scrollphat.update()
    def draw(self, game):

        text = game.get_scroller_text()

        if text != '':

           scrollphat.write_string(text)
           scrollphat.scroll()
           time.sleep(0.06)

        else:

            scrollphat.clear()

            for x, y in game.get_pixels():
                pixel = int(x), int(y)
                scrollphat.set_pixel(pixel[0], pixel[1], 1)

            scrollphat.update()
Beispiel #39
0
def mainprog():
	"Display current time with pixels on the Scroll pHAT."
	global disp

	t = time.strftime(f, time.localtime())
	h1, h2, m1, m2 = [int(x) for x in t]
	disp = [[2, 4, 4, 4, 1, 6, 6, 1, 8, 8, 8] for y in range(3)]
	tog( 0,  1, h1, 3)
	tog( 1,  4, h2, 5)
	tog( 5,  7, m1, 7)
	tog( 8, 11, m2, 9)
	for x in range(11):
		for y in range(3):
			r, g, b = colors[ disp[y][x] ]
			if (r+g+b>0):
				scrollphat.set_pixel(x, y+1, 1)
			else:
				scrollphat.set_pixel(x, y+1, 0)
	scrollphat.update()
Beispiel #40
0
    def dance(self):
        '''Displays the space invader dancing'''

        if self.args.verbose:
            print('Running SpaceInvader.dance')
            print('Dancing for {} times'.format(self.args.dance_times))

        for i in range(0, self.args.dance_times):

            # Arm Down
            self.armDownDisplay(0)
            scrollphat.update()
            time.sleep(args.pause_dance)
            scrollphat.clear()

            # Arm Up
            self.armUpDisplay(0)
            scrollphat.update()
            time.sleep(args.pause_dance)
            scrollphat.clear()
Beispiel #41
0
def render():
    # LED check
    scrollphat.clear_buffer()
    for col in range(0, 13):
        if col > 1:
            scrollphat.set_col(col - 2, 0)
        if col < 11:
            scrollphat.set_col(col, 0b11111)
        scrollphat.update()
        time.sleep(.1)

    time.sleep(.3)

    while _running:
        scrollphat.clear_buffer()
        # ``_output`` access should be thread-safe; de-referenced just once
        for rend, value in zip(DISPLAY, _output):
            try:
                rend(value, scrollphat)
            except ValueError as e:
                logging.warn(e, exc_info=True)
        scrollphat.update()
        time.sleep(.05)
def showmotor(controller, row, motorval):
        if controller == "ab":
                row = row + 6

        #print motorval

        if motorval == 0:
                for n in range(5):
                        scrollphat.set_pixel(row,n,0)
                        scrollphat.update()
        else:
                steps = int(round((abs(motorval) - BASE_MOTOR_POWER) / 21))
                for n in range(5):
                        if n <= steps:
                                scrollphat.set_pixel(row,n,1)
                                scrollphat.update()
                        else:
                                scrollphat.set_pixel(row,n,0)
                                scrollphat.update()

        return
Beispiel #43
0
def switchoff():
        for x in range(11):
                for y in range(5):
                        scrollphat.set_pixel(x,y,0)
                        scrollphat.update();
import scrollphat as hat
import time

str = 'Merry Christmas   '
hat.set_brightness(2)
hat.write_string(str)

# for i in range(len(str) * 5):
#     hat.scroll()
#     time.sleep(0.150)

hat.graph([2, 4, 6, 8, 10, 8, 6, 4, 2, 0, 3])
hat.update()

Beispiel #45
0
#!/usr/bin/env python

"""lights a single led. The function set_pixel() takes 3 arguments - x position (in a range 0-10), y position (range 0-4) and off/on (0/1). The position of an led is given top-to-bottom, left-to-right with the scrollphat positioned so that 'scroll pHAT' is along the bottom edge and 'PIMORONI.COM' runs along the right-hand short edge."""

import scrollphat

#sets a single pixel to 'on' - in this case it is the pixel in the second from left column in the middle row 
scrollphat.set_pixel(1,2,0)
scrollphat.update();
Beispiel #46
0
	# for smiley in smileys:
	# 	scrollphat.clear()
	# 	scrollphat.write_string(smiley, 2)
	# 	time.sleep(0.5)

sys.exit()
#scrollphat.update()
buf = [0] * 11
while True:
	for x in range(0, 11):
		y = (math.sin(((i)+(x*10.0))/10.0) + 1) * 2.5
		y = int(y)
		y2 = (math.sin(((i/2.0)+(x*10.0))/10.0) + 1) * 2.5
		y2 = int(y2)
		buf[x] = 1 << y
		#buf[x] |= 1 << y2

	scrollphat.update(buf)

	time.sleep(0.005)

	i += 1
#     # buf = [0] * 11
#     # t = millis()/50
#     # for o_x in range(11):
#     #     x = t + (o_x/3.0)
#     #     y = int((math.sin(x) + 1) * 2.5)
#     #     buf[o_x] |= (1 << y)

#
import time
import sys
from random import randint

i = 0
buf = [0] * 11

while True:
    clear = (randint(0,1000)) # rnd var for timing of crashes
    change_brightness = (randint(0,2))
    if change_brightness == 2:
        sp.set_brightness(randint(1,128))
    y = randint(0,4)
    x = randint(0,10)
    sp.set_pixel(x,y,(randint(0,1)))
    sp.update()
    time.sleep(0.02)
    for r in range(0,2):
        y = randint(0,4)
        x = randint(0,10)
        sp.set_pixel(x,y,0)
        sp.update()
        time.sleep(0.01)
    if clear > 993:
        if clear > 996:
            for w in range(0,randint(3,9)):
                for x in range(0,11):
                    for y in range(0,5):
                        sp.set_pixel(x,y,randint(0,1))
                        sp.set_brightness(128)
                sp.update()
def clear(pause):
    for y in range(5):
        for x in range(11):
            scrollphat.set_pixel(x,y,0)
            scrollphat.update()
            time.sleep(pause)
Beispiel #49
0
#!/usr/bin/env python

import scrollphat
import math
import time
import sys

i = 0
buf = [0] * 11
scrollphat.set_brightness(20)

while True:
    try:
        for x in range(0, 11):
            y = math.sin((i + (x * 10)) / 10.0) + 1  # Produces range from 0 to 2
            y *= 2.5  # Scale to 0 to 5
            buf[x] = 1 << int(y)

        scrollphat.set_buffer(buf)
        scrollphat.update()

        time.sleep(0.005)

        i += 1
    except KeyboardInterrupt:
        scrollphat.clear()
        sys.exit(-1)
Beispiel #50
0
w, h = (11, 5)					# Setting width and height
x, y = (0, 0)					# Setting x and y 

grav = 0.5					# Setting Gravity
jump_vel = 0					# Setting jump velocity
jump_decay = 0.8				# Setting jump decay

move_speed = 1					# Setting movement speed

while True:					# Loop forever

    scrollphat.clear()				# Clearing the display
    scrollphat.set_brightness(brightness)	# Getting the brightness for LEDS
    scrollphat.set_pixel(int(x), int(y), 1)	# Setting pixel to show in bottom left corner
    scrollphat.update()				# Updating scroll phat	
    time.sleep(0.03)				# Set scroll phat to sleep for .3 seconds

    pygame.event.pump()				# Processes pygame event handlers internally

    axis_value = joystick.get_axis(0)		# Setting axis value for x

    if axis_value > 0.8:			# If axis value is greater than 0.8 
        x += move_speed				# increase move speed of x
    elif axis_value < -0.8:			# If axis value is less than 0.8
        x -= move_speed				# Decrease move speed

    if x >= w:					# if x is greater than width
        x = w - 1				# x = width - 1
    elif x < 0:					# If x is less than 0
        x = 0					# x is equal to 0
 def __init__(self, brightness):
     scrollphat.set_brightness(brightness)
     scrollphat.clear()
     scrollphat.update()
Beispiel #52
0
def status(status):

    scrollphat.set_pixel(10,4,status)
    scrollphat.update()
Beispiel #53
0
def displaySprite(sprite):
    for rowNum, row in sprite:
        for colNum, cell in row:
            setCell(rowNum, colNum, cell)
    scrollphat.update()
Beispiel #54
0
def switchon():
        for x in range(11):
                for y in range(5):
                        scrollphat.set_brightness(4)
                        scrollphat.set_pixel(x,y,1)
                        scrollphat.update();
Beispiel #55
0
s.set_pixel(5, 0, 1)
s.set_pixel(4, 1, 1)
s.set_pixel(4, 3, 1)
s.set_pixel(3, 2, 1)
s.set_pixel(4, 2, 1)
s.set_pixel(5, 2, 1)
s.set_pixel(6, 2, 1)
s.set_pixel(7, 2, 1)
s.set_pixel(8, 2, 1)
s.set_pixel(9, 2, 1)
s.set_pixel(10, 2, 1)


while True:
	s.scroll()
	s.update()
	time.sleep(0.05)













def paint(pause):
    for y in range(5):
        for x in range(11):
            scrollphat.set_pixel(x,y,1)
            scrollphat.update()
            time.sleep(pause)