]>
vault307.fbx.one Git - PicoTamachibi.git/blob - main.py
f6167ed608d13fc54b2b0c06610398d1df8a5080
1 from machine
import I2C
, Pin
2 from ssd1306
import SSD1306_I2C
3 from icon
import Animate
, Icon
, Toolbar
, Button
, Event
17 i2c
= I2C(id=id, sda
=sda
, scl
=scl
)
19 oled
= SSD1306_I2C(width
=128, height
=64, i2c
=i2c
)
27 food
= Icon('food.pbm', width
=16, height
=16, name
="food")
28 lightbulb
= Icon('lightbulb.pbm', width
=16, height
=16, name
="lightbulb")
29 game
= Icon('game.pbm', width
=16, height
=16, name
="game")
30 firstaid
= Icon('firstaid.pbm', width
=16, height
=16, name
="firstaid")
31 toilet
= Icon('toilet.pbm', width
=16, height
=16, name
="toilet")
32 heart
= Icon('heart.pbm', width
=16, height
=16, name
="heart")
33 call
= Icon('call.pbm', width
=16, height
=16, name
="call")
34 save
= Icon('disc.pbm', width
=16, height
=16, name
="toilet")
37 """ Clear the screen """
38 oled
.fill_rect(0,0,128,64,0)
40 # def animate(frames, timer):
41 # for frame in frames:
42 # oled.blit(frame.image, frame.x, frame.y)
50 toolbar
.additem(lightbulb
)
52 toolbar
.additem(firstaid
)
53 toolbar
.additem(toilet
)
54 toolbar
.additem(heart
)
60 poopy
= Animate(x
=96,y
=48, width
=16, height
=16, filename
='poop')
61 baby
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='baby_bounce', animation_type
='bounce')
62 eat
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='eab: 20t')
63 babyzzz
= Animate(animation_type
="loop", x
=48,y
=16, width
=48, height
=48, filename
='baby_zzz')
64 death
= Animate(animation_type
='bounce', x
=40,y
=16, width
=16, height
=16, filename
="skull")
65 go_potty
= Animate(filename
="potty", animation_type
='bounce',x
=64,y
=16, width
=48, height
=48)
66 call_animate
= Animate(filename
='call_animate', width
=16, height
=16, x
=108, y
=0)
67 call_animate
.speed
= 'very slow'
69 #button_jleft = Button(20)
70 #button_jright = Button(19)
71 #button_jup = Button(22)
72 #button_jdown = Button(21)
73 #button_jmid = Button(18)
74 #button_jset = Button(17)
75 #button_jrst = Button(16)
93 def __init__(self
, set="default"):
94 self
.__ActiveConfig
=self
.Configurations
[set]
97 def ActiveConfig(self
):
98 return self
.__ActiveConfig
104 def __init__(self
,config
):
105 for button
in config
.ActiveConfig
:
106 self
.PinObjects
[button
]=Pin(config
.ActiveConfig
[button
])
108 ButtonSetup
=ButtonConfig()
109 InputDevice
=controller(ButtonSetup
)
112 tb
.select(index
, oled
)
119 energy_increase
= Event(name
="Increase Energy", sprite
=heart
, value
=1)
120 firstaid
= Event(name
="First Aid", sprite
=firstaid
, value
=0)
121 toilet
= Event(name
="Toilet", sprite
=toilet
, value
=0)
122 greatgame
= Event(name
="Gaming", sprite
=game
, value
=0)
123 # poop_event = Event(name="poop time", sprite=poop_sprite, callback=poop_check())
124 sleep_time
= Event(name
="sleep time", sprite
=lightbulb
, value
=1)
125 heart_status
= Event(name
="Status", sprite
=heart
)
126 # poop_event.timer = 3
127 # poop_event.timer_ms = 1
133 babyzzz
.speed
= 'very slow'
141 tb
.unselect(index
, oled
)
142 if InputDevice
.PinObjects
["left"].value():
145 index
= tb
.getlength()-1
147 if InputDevice
.PinObjects
["right"].value():
149 if index
== tb
.getlength():
152 if InputDevice
.PinObjects
["cancel"].value():
157 tb
.select(index
, oled
)
159 if InputDevice
.PinObjects
["action"].value():
160 if tb
.selected_item
== "food":
165 if tb
.selected_item
== "game":
166 greatgame
.message
= "Gaming!!!"
167 greatgame
.popup(oled
=oled
)
170 greatgame
.message
= "happy = " + str(happiness
)
171 greatgame
.popup(oled
)
172 greatgame
.message
= "energy = " + str(energy
)
173 greatgame
.popup(oled
)
175 print("game:\n energy = " + str(energy
)+"\n happy = " + str(happiness
))
176 if tb
.selected_item
== "toilet":
177 toilet
.message
= "Cleaning..."
178 toilet
.popup(oled
=oled
)
184 if tb
.selected_item
== "lightbulb":
188 sleep_time
.message
= "Night Night"
189 sleep_time
.popup(oled
)
191 # need to add an event that increases energy level after sleeping for 1 minute
196 if tb
.selected_item
== "firstaid":
197 firstaid
.message
= "Vitamins"
198 firstaid
.popup(oled
=oled
)
202 if tb
.selected_item
== "heart":
203 heart_status
.message
= "health = " + str(health
)
204 heart_status
.popup(oled
)
205 heart_status
.message
= "happy = " + str(happiness
)
206 heart_status
.popup(oled
)
207 heart_status
.message
= "energy = " + str(energy
)
208 heart_status
.popup(oled
)
210 if tb
.selected_item
== "call":
211 # call_animate.animate(oled)
212 # call_animate.set = False
223 if feeding_time
and eat
.done
:
225 energy_increase
.message
= "ENERGY + 1"
226 energy_increase
.popup(oled
=oled
)
234 babyzzz
.animate(oled
)
240 go_potty
.animate(oled
)
248 if (energy
<= 1) and (happiness
<= 1) and (health
<=1):
253 #if (energy <= 1) or (happiness <= 1) or (health <= 1):
254 # set the toolbar call icon to flash
255 # call_animate.set = True
257 # call_animate.set = False
266 tb
.select(index
, oled
)
268 # if call_animate.set:
269 # call_animate.animate(oled)