]>
vault307.fbx.one Git - PicoTamachibi.git/blob - main.py
1 from machine
import I2C
, Pin
2 from ssd1306
import SSD1306_I2C
3 from icon
import Animate
, Icon
, Toolbar
, Button
, Event
12 #Forking and pulling- yeah - Lu was here :>
18 i2c
= I2C(id=id, sda
=sda
, scl
=scl
)
20 oled
= SSD1306_I2C(width
=128, height
=64, i2c
=i2c
)
28 food
= Icon('food.pbm', width
=16, height
=16, name
="food")
29 lightbulb
= Icon('lightbulb.pbm', width
=16, height
=16, name
="lightbulb")
30 game
= Icon('game.pbm', width
=16, height
=16, name
="game")
31 firstaid
= Icon('firstaid.pbm', width
=16, height
=16, name
="firstaid")
32 toilet
= Icon('toilet.pbm', width
=16, height
=16, name
="toilet")
33 heart
= Icon('heart.pbm', width
=16, height
=16, name
="heart")
34 call
= Icon('call.pbm', width
=16, height
=16, name
="call")
35 save
= Icon('disc.pbm', width
=16, height
=16, name
="toilet")
38 """ Clear the screen """
39 oled
.fill_rect(0,0,128,64,0)
41 # May the Force be with you // Patrick
43 # def animate(frames, timer):
44 # for frame in frames:
45 # oled.blit(frame.image, frame.x, frame.y)
53 toolbar
.additem(lightbulb
)
55 toolbar
.additem(firstaid
)
56 toolbar
.additem(toilet
)
57 toolbar
.additem(heart
)
63 poopy
= Animate(x
=96,y
=48, width
=16, height
=16, filename
='poop')
64 baby
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='baby_bounce', animation_type
='bounce')
65 eat
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='eab: 20t')
66 babyzzz
= Animate(animation_type
="loop", x
=48,y
=16, width
=48, height
=48, filename
='baby_zzz')
67 death
= Animate(animation_type
='bounce', x
=40,y
=16, width
=16, height
=16, filename
="skull")
68 go_potty
= Animate(filename
="potty", animation_type
='bounce',x
=64,y
=16, width
=48, height
=48)
69 call_animate
= Animate(filename
='call_animate', width
=16, height
=16, x
=108, y
=0)
70 call_animate
.speed
= 'very slow'
72 #button_jleft = Button(20)
73 #button_jright = Button(19)
74 #button_jup = Button(22)
75 #button_jdown = Button(21)
76 #button_jmid = Button(18)
77 #button_jset = Button(17)
78 #button_jrst = Button(16)
96 def __init__(self
, set="default"):
97 self
.__ActiveConfig
=self
.Configurations
[set]
100 def ActiveConfig(self
):
101 return self
.__ActiveConfig
107 def __init__(self
,config
):
108 for button
in config
.ActiveConfig
:
109 self
.PinObjects
[button
]=Pin(config
.ActiveConfig
[button
])
111 ButtonSetup
=ButtonConfig()
112 InputDevice
=controller(ButtonSetup
)
115 tb
.select(index
, oled
)
122 energy_increase
= Event(name
="Increase Energy", sprite
=heart
, value
=1)
123 firstaid
= Event(name
="First Aid", sprite
=firstaid
, value
=0)
124 toilet
= Event(name
="Toilet", sprite
=toilet
, value
=0)
125 greatgame
= Event(name
="Gaming", sprite
=game
, value
=0)
126 # poop_event = Event(name="poop time", sprite=poop_sprite, callback=poop_check())
127 sleep_time
= Event(name
="sleep time", sprite
=lightbulb
, value
=1)
128 heart_status
= Event(name
="Status", sprite
=heart
)
129 # poop_event.timer = 3
130 # poop_event.timer_ms = 1
136 babyzzz
.speed
= 'very slow'
144 tb
.unselect(index
, oled
)
145 if InputDevice
.PinObjects
["left"].value():
148 index
= tb
.getlength()-1
150 if InputDevice
.PinObjects
["right"].value():
152 if index
== tb
.getlength():
155 if InputDevice
.PinObjects
["cancel"].value():
160 tb
.select(index
, oled
)
162 if InputDevice
.PinObjects
["action"].value():
163 if tb
.selected_item
== "food":
168 if tb
.selected_item
== "game":
169 greatgame
.message
= "Gaming!!!"
170 greatgame
.popup(oled
=oled
)
173 greatgame
.message
= "happy = " + str(happiness
)
174 greatgame
.popup(oled
)
175 greatgame
.message
= "energy = " + str(energy
)
176 greatgame
.popup(oled
)
178 print("game:\n energy = " + str(energy
)+"\n happy = " + str(happiness
))
179 if tb
.selected_item
== "toilet":
180 toilet
.message
= "Cleaning..."
181 toilet
.popup(oled
=oled
)
187 if tb
.selected_item
== "lightbulb":
191 sleep_time
.message
= "Night Night"
192 sleep_time
.popup(oled
)
194 # need to add an event that increases energy level after sleeping for 1 minute
199 if tb
.selected_item
== "firstaid":
200 firstaid
.message
= "Vitamins"
201 firstaid
.popup(oled
=oled
)
205 if tb
.selected_item
== "heart":
206 heart_status
.message
= "health = " + str(health
)
207 heart_status
.popup(oled
)
208 heart_status
.message
= "happy = " + str(happiness
)
209 heart_status
.popup(oled
)
210 heart_status
.message
= "energy = " + str(energy
)
211 heart_status
.popup(oled
)
213 if tb
.selected_item
== "call":
214 # call_animate.animate(oled)
215 # call_animate.set = False
226 if feeding_time
and eat
.done
:
228 energy_increase
.message
= "ENERGY + 1"
229 energy_increase
.popup(oled
=oled
)
237 babyzzz
.animate(oled
)
243 go_potty
.animate(oled
)
251 if (energy
<= 1) and (happiness
<= 1) and (health
<=1):
256 #if (energy <= 1) or (happiness <= 1) or (health <= 1):
257 # set the toolbar call icon to flash
258 # call_animate.set = True
260 # call_animate.set = False
269 tb
.select(index
, oled
)
271 # if call_animate.set:
272 # call_animate.animate(oled)