diff --git a/flow3r.toml b/flow3r.toml index a61cec5b5d918ef9d90ec2fd9db6d38e1f133f40..9745324320268857501e5a6bc0092b90cb08f19c 100644 --- a/flow3r.toml +++ b/flow3r.toml @@ -17,7 +17,7 @@ author = "Roxy" license = "MIT" # URL to the repository of your app. -url = "https://git.flow3r.garden/roxy/blobfox" +url = "Roxy/blobfox" # Description of your app. Maximum 140 characters! description = "express your emotions with blobfoxes and the leds" diff --git a/main.py b/main.py index fd7d39db828b7114ee72367ebabe29da0701e15a..38e6fb36aa6dca8ffcd738ef3e82269f61344766 100644 --- a/main.py +++ b/main.py @@ -17,6 +17,60 @@ from st3m.reactor import Responder from ctx import Context import st3m.run +import leds + +button_leds = [ + [37,38,39,0,1,2,3], # top north + [2,3,4,5,6], # buttom north east + [5,6,7,8,9,10,11], # top east + [10,11,12,13,14], # buttom east + [13,14,15,16,17,18,19], # top south east + [18,19,20,21,22], # buttom south + [21,22,23,24,25,26,27], # top south west + [26,27,28,29,30], # buttom west + [29,30,31,32,33,34,35], # top west + [34,35,36,37,38], # buttom north west +] + +emoji_colors = { + # happy + '1f642': (255,255,0), + '1f600': (255,215,0), # grinning + '1f60c': (255,0,0), # relieved + '1f63a': (255,0,255), # smile cat + '1f60a': (255, 0, 127), # blush + '1f604': (255, 127, 0), # eyes closed smile + # laugh + '1f603': (255, 255, 0), + '1f602': (202, 34, 96), # tears of joy + '1f606': (255, 215, 0), # grin + '1f639': (255, 0, 255), # tears of joy cat + '1f92a': (255, 0, 127), # crazy + '1f973': (255, 127, 0), # party + # cool + '1f60e': (0, 0, 255), + '1f607': (255, 200, 220), # halo + '1f974': (255, 215, 0), # weird + '1f92a': (255, 0, 255), # crazy + '1f973': (255, 0, 127), # party + '1f608': (255, 0, 255), # evil + # sad + '1f615': (0, 0, 255), + '1f614': (255, 215, 0), # pensive + '1f61e': (202, 34, 96), # disappointed + '1f622': (255, 0, 255), # cry + '1f62d': (255, 0, 127), # cry cat + '1f62a': (255, 127, 0), # angry + # love + '1f970': (255, 0, 255), + '1f60d': (240, 40, 0), # heart eyes + '1f618': (240, 0, 40), # heart kiss + '1f63b': (255, 0, 0), # heart eyes cat + '1f619': (140, 0, 20), # closed eyed kiss + '1f917': (255, 100, 100), # hug + +} + top_menu_emojis = [ 'blobfox', # happy 'blobfoxhappy', # laugh @@ -63,6 +117,58 @@ sub_menu_emojis = [ ], ] +emoji_colors = { + # happy + 'blobfox': (255,255,0), + 'blobfoxhappy': (255,215,0), + 'blobfoxhappymlem': (255,0,0), + 'blobfoxreachaww': (255,0,255), + 'blobfoxmischievous': (255, 0, 127), + 'blobfoxsnug': (255, 127, 0), + # laugh + 'blobfoxlaugh': (255, 255, 0), + 'blobfoxboop': (202, 34, 96), + 'blobfoxboophappy': (255, 215, 0), + 'blobfoxcomfy': (255, 0, 255), + 'blobfoxcomfyhappy': (255, 0, 255), + 'blobfoxgoogly': (255, 0, 127), + # cool + 'blobfoxcool': (0, 0, 255), + 'blobfoxdealwithit': (255, 200, 220), + 'blobfoxninja': (255, 215, 0), + 'blobfoxnerd': (255, 0, 255), + 'blobfoxdab': (255, 0, 127), + 'blobfoxpirate': (255, 0, 255), + # sad + 'blobfoxsad': (0, 0, 255), + 'blobfoxterrified': (255, 215, 0), + 'blobfoxcryreach': (202, 34, 96), + 'blobfoxcry': (255, 0, 255), + 'blobfoxmeltsob': (255, 0, 127), + # love + 'blobfoxfloof': (255, 0, 255), + 'blobfoxfloof_w_': (240, 40, 0), + 'blobfoxfloofhappy': (240, 0, 40), + 'blobfoxfloofcute': (255, 0, 0), + 'blobfoxfloofdevil': (140, 0, 20), + 'blobfoxfloofreach': (255, 100, 100), +} + +# switch off all leds +def leds_off(): + for i in range(0, 40): + leds.set_rgb(i, 0, 0, 0) + +def leds_all_color(r: int, g: int, b: int): + for i in range(0, 40): + leds.set_rgb(i, r, g, b) + + +# switch on the leds for the button +def leds_petal_on(petal: int, r: int, g: int, b: int): + for i in button_leds[petal]: + leds.set_rgb(i, r, g, b) + class App(Application): def __init__(self, app_ctx: ApplicationContext) -> None: super().__init__(app_ctx) @@ -71,10 +177,10 @@ class App(Application): self.current = 0 self.last = 0 - self.emoji_dir = os.path.join(app_ctx.bundle_path, 'assets/blobfoxes/') - self.emojis = os.listdir(self.emoji_dir) - print(self.emoji_dir) - print(self.emojis) + self.blobfox_dir = os.path.join(app_ctx.bundle_path, 'assets/blobfoxes/') + self.blobfoxes = os.listdir(self.blobfox_dir) + print(self.blobfox_dir) + print(self.blobfoxes) self.emoji = 'blobfox' @@ -83,9 +189,9 @@ class App(Application): def draw(self, ctx: Context) -> None: # Paint the background black ctx.rgb(0, 0, 0).rectangle(-144, -144, 288, 288).fill() - emoji_filename = next((x for x in self.emojis if x.startswith(self.emoji))) + emoji_filename = next((x for x in self.blobfoxes if x.startswith(self.emoji))) if emoji_filename: - ctx.image(os.path.join(self.emoji_dir, emoji_filename), -80, -80, 160, 160) + ctx.image(os.path.join(self.blobfox_dir, emoji_filename), -80, -80, 160, 160) def think(self, ins: InputState, delta_ms: int) -> None: @@ -99,24 +205,24 @@ class App(Application): self.i -= 1 if self.i < 0: - self.i = len(self.emojis) - 1 + self.i = len(self.blobfoxes) - 1 - self.emoji = self.emojis[self.i] + self.emoji = self.blobfoxes[self.i] elif direction == ins.buttons.PRESSED_RIGHT: if (self.current - self.last) > 100: self.last = self.current self.i += 1 - if self.i >= len(self.emojis): + if self.i >= len(self.blobfoxes): self.i = 0 - self.emoji = self.emojis[self.i] + self.emoji = self.blobfoxes[self.i] - #if self.emoji in emoji_colors: - # leds_all_color(*emoji_colors[self.emoji]) - #else: - # leds_off() + if self.emoji in emoji_colors: + leds_all_color(*emoji_colors[self.emoji]) + else: + leds_off() for i in range(0, 10): petal = ins.captouch.petals[i] @@ -125,13 +231,13 @@ class App(Application): self.top_menu_selection = int(i/2) # print('top menu',self.top_menu_selection) self.emoji = top_menu_emojis[self.top_menu_selection] - #leds_petal_on(i,255,0,0) + leds_petal_on(i,255,0,0) else: self.sub_menu_selection = int(i/2) # print('sub menu',self.sub_menu_selection) self.emoji = sub_menu_emojis[self.top_menu_selection][self.sub_menu_selection] - #leds_petal_on(i,0,0,255) - #leds.update() + leds_petal_on(i,0,0,255) + leds.update() if __name__ == '__main__': # Continue to make runnable via mpremote run.