Example #1
0
    def main(f):
        phrases = [
            "It is certain.", "It is decidedly so.", "Without a doubt.",
            "Yes - definitely.", "You may rely on it.", "As I see it, yes.",
            "Most likely.", "Outlook good.", "Yes.", "Signs point to yes.",
            "Reply hazy, try again", "Ask again later.",
            "Better not tell you now.", "Cannot predict now.",
            "Concentrate and ask again.", "Don't count on it.",
            "My reply is no.", "My sources say no.", "Outlook not so good.",
            "Very doubtful."
        ]
        i2c = machine.I2C(scl=Pin(22), sda=Pin(21))
        epd.init()
        epd.set_rotate(gxgde0213b1.ROTATE_270)
        epd.clear_frame(fb)
        epd.display_frame(fb)
        prev_orientation = None

        keep_on = [True]

        def exit_loop():
            keep_on[0] = False

        exit_button = TouchButton(Pin(32), exit_loop)

        while keep_on[0]:
            exit_button.read()
            orientation = MagicBall.get_orientation(i2c)

            if orientation and orientation != prev_orientation:
                if orientation == 'upright':
                    MagicBall.show_message(urandom.choice(phrases))
                elif orientation == 'prone':
                    MagicBall.clear_screen()
            prev_orientation = orientation
Example #2
0
    def main(f):
        i2c = machine.I2C(scl=Pin(22), sda=Pin(21))
        epd.init()
        epd.set_rotate(gxgde0213b1.ROTATE_270)
        epd.clear_frame(fb)
        epd.display_frame(fb)
        keep_on = [True]

        def exit_loop():
            keep_on[0] = False

        exit_button = TouchButton(Pin(32), exit_loop)

        while keep_on[0]:
            exit_button.read()
            orientation = Accelerometer.get_orientation(i2c)
            x = "x={0}".format(orientation[0])
            y = "y={0}".format(orientation[1])
            z = "z={0}".format(orientation[2])
            print(x, y, z)
            epd.clear_frame(fb)
            epd.set_rotate(gxgde0213b1.ROTATE_270)
            epd.display_string_at(fb, 10, 0, x, font16, gxgde0213b1.COLORED)
            epd.display_string_at(fb, 10, 24, y, font16, gxgde0213b1.COLORED)
            epd.display_string_at(fb, 10, 48, z, font16, gxgde0213b1.COLORED)
            epd.display_frame(fb)
            time.sleep(1)
Example #3
0
    def handleKey(self, key):
        f = self.cur_opt['function']
        if key == "up":
            self.move(-1)
        elif key == "down":
            self.move(1)
        elif key == "right":
            self.move(8)
        elif key == "left":
            self.move(-8)
        elif key == "launch":
            if f != None:
                print("Launching %s" % f)
                epd.init()
                epd.clear_frame(fb)
                epd.display_string_at(fb, 0, 0, "Launching", font16,
                                      gxgde0213b1.COLORED)
                epd.display_string_at(fb, 0, 16, self.cur_opt['text'] + " ..",
                                      font16, gxgde0213b1.COLORED)
                epd.display_frame(fb)
                time.sleep(1)
                f(self.cur_opt['text'])
                epd.clear_frame(fb)
                epd.display_string_at(fb, 0, 0, "App Finished!", font16,
                                      gxgde0213b1.COLORED)
                epd.display_string_at(fb, 0, 16, self.cur_opt['text'] + " ..",
                                      font16, gxgde0213b1.COLORED)
                epd.display_frame(fb)
                time.sleep(1)
                epd.clear_frame(fb)
                epd.display_frame(fb)
                epd.initPart()

            else:
                print("Could not launch '%s' no function attatched!" %
                      self.cur_opt['text'])
Example #4
0
 def show_message(message):
     epd.init()
     epd.clear_frame(fb)
     epd.display_string_at(fb, 0, 52, message, font16, gxgde0213b1.COLORED)
     epd.display_frame(fb)