]>
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
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 # May the Force be with you // Patrick
42 # def animate(frames, timer):
43 # for frame in frames:
44 # oled.blit(frame.image, frame.x, frame.y)
52 toolbar
.additem(lightbulb
)
54 toolbar
.additem(firstaid
)
55 toolbar
.additem(toilet
)
56 toolbar
.additem(heart
)
62 poopy
= Animate(x
=96,y
=48, width
=16, height
=16, filename
='poop')
63 baby
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='baby_bounce', animation_type
='bounce')
64 eat
= Animate(x
=48,y
=16, width
=48, height
=48, filename
='eab: 20t')
65 babyzzz
= Animate(animation_type
="loop", x
=48,y
=16, width
=48, height
=48, filename
='baby_zzz')
66 death
= Animate(animation_type
='bounce', x
=40,y
=16, width
=16, height
=16, filename
="skull")
67 go_potty
= Animate(filename
="potty", animation_type
='bounce',x
=64,y
=16, width
=48, height
=48)
68 call_animate
= Animate(filename
='call_animate', width
=16, height
=16, x
=108, y
=0)
69 call_animate
.speed
= 'very slow'
71 #button_jleft = Button(20)
72 #button_jright = Button(19)
73 #button_jup = Button(22)
74 #button_jdown = Button(21)
75 #button_jmid = Button(18)
76 #button_jset = Button(17)
77 #button_jrst = Button(16)
95 def __init__(self
, set="default"):
96 self
.__ActiveConfig
=self
.Configurations
[set]
99 def ActiveConfig(self
):
100 return self
.__ActiveConfig
106 def __init__(self
,config
):
107 for button
in config
.ActiveConfig
:
108 self
.PinObjects
[button
]=Pin(config
.ActiveConfig
[button
])
110 ButtonSetup
=ButtonConfig()
111 InputDevice
=controller(ButtonSetup
)
114 tb
.select(index
, oled
)
121 energy_increase
= Event(name
="Increase Energy", sprite
=heart
, value
=1)
122 firstaid
= Event(name
="First Aid", sprite
=firstaid
, value
=0)
123 toilet
= Event(name
="Toilet", sprite
=toilet
, value
=0)
124 greatgame
= Event(name
="Gaming", sprite
=game
, value
=0)
125 # poop_event = Event(name="poop time", sprite=poop_sprite, callback=poop_check())
126 sleep_time
= Event(name
="sleep time", sprite
=lightbulb
, value
=1)
127 heart_status
= Event(name
="Status", sprite
=heart
)
128 # poop_event.timer = 3
129 # poop_event.timer_ms = 1
135 babyzzz
.speed
= 'very slow'
143 tb
.unselect(index
, oled
)
144 if InputDevice
.PinObjects
["left"].value():
147 index
= tb
.getlength()-1
149 if InputDevice
.PinObjects
["right"].value():
151 if index
== tb
.getlength():
154 if InputDevice
.PinObjects
["cancel"].value():
159 tb
.select(index
, oled
)
161 if InputDevice
.PinObjects
["action"].value():
162 if tb
.selected_item
== "food":
167 if tb
.selected_item
== "game":
168 greatgame
.message
= "Gaming!!!"
169 greatgame
.popup(oled
=oled
)
172 greatgame
.message
= "happy = " + str(happiness
)
173 greatgame
.popup(oled
)
174 greatgame
.message
= "energy = " + str(energy
)
175 greatgame
.popup(oled
)
177 print("game:\n energy = " + str(energy
)+"\n happy = " + str(happiness
))
178 if tb
.selected_item
== "toilet":
179 toilet
.message
= "Cleaning..."
180 toilet
.popup(oled
=oled
)
186 if tb
.selected_item
== "lightbulb":
190 sleep_time
.message
= "Night Night"
191 sleep_time
.popup(oled
)
193 # need to add an event that increases energy level after sleeping for 1 minute
198 if tb
.selected_item
== "firstaid":
199 firstaid
.message
= "Vitamins"
200 firstaid
.popup(oled
=oled
)
204 if tb
.selected_item
== "heart":
205 heart_status
.message
= "health = " + str(health
)
206 heart_status
.popup(oled
)
207 heart_status
.message
= "happy = " + str(happiness
)
208 heart_status
.popup(oled
)
209 heart_status
.message
= "energy = " + str(energy
)
210 heart_status
.popup(oled
)
212 if tb
.selected_item
== "call":
213 # call_animate.animate(oled)
214 # call_animate.set = False
225 if feeding_time
and eat
.done
:
227 energy_increase
.message
= "ENERGY + 1"
228 energy_increase
.popup(oled
=oled
)
236 babyzzz
.animate(oled
)
242 go_potty
.animate(oled
)
250 if (energy
<= 1) and (happiness
<= 1) and (health
<=1):
255 #if (energy <= 1) or (happiness <= 1) or (health <= 1):
256 # set the toolbar call icon to flash
257 # call_animate.set = True
259 # call_animate.set = False
268 tb
.select(index
, oled
)
270 # if call_animate.set:
271 # call_animate.animate(oled)