Skip to content

Commit 07428a1

Browse files
authored
Merge branch 'master' into master
2 parents 7cdeccc + 152c41f commit 07428a1

18 files changed

+1112
-29
lines changed

FONA_SMS_Sensor/code.py

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# pylint: disable=unused-import
12
import time
23
import board
34
import busio
45
import digitalio
56
from adafruit_fona.adafruit_fona import FONA
7+
from adafruit_fona.fona_3g import FONA3G
68
import adafruit_bme280
79

810
print("FONA SMS Sensor")
@@ -11,9 +13,12 @@
1113
uart = busio.UART(board.TX, board.RX)
1214
rst = digitalio.DigitalInOut(board.D4)
1315

14-
# Initialize FONA module (this may take a few seconds)
16+
# Use this for FONA800 and FONA808
1517
fona = FONA(uart, rst)
1618

19+
# Use this for FONA3G
20+
# fona = FONA3G(uart, rst)
21+
1722
# Initialize BME280 Sensor
1823
i2c = busio.I2C(board.SCL, board.SDA)
1924
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
@@ -28,23 +33,11 @@
2833
# Enable FONA SMS notification
2934
fona.enable_sms_notification = True
3035

31-
# store incoming notification info
32-
notification_buf = bytearray(64)
33-
34-
print("FONA Ready!")
36+
print("Listening for messages...")
3537
while True:
36-
if fona.in_waiting: # data is available from FONA
37-
notification_buf = fona.read_line()[1]
38-
# Split out the sms notification slot num.
39-
notification_buf = notification_buf.decode()
40-
if "+CMTI:" not in notification_buf:
41-
continue
42-
sms_slot = notification_buf.split(",")[1]
43-
44-
print("NEW SMS!\n\t Slot: ", sms_slot)
45-
46-
# Get SMS message and address
47-
sender, message = fona.read_sms(sms_slot)
38+
sender, message = fona.receive_sms()
39+
if message:
40+
print("New Message!")
4841
print("FROM: ", sender)
4942
print("MSG: ", message)
5043

@@ -57,16 +50,17 @@
5750
message = message.lower()
5851
message = message.strip()
5952

60-
if message in ['temp', 'temperature', 't']:
53+
if message in ["temp", "temperature", "t"]:
6154
response = "Temperature: %0.1f C" % temp
62-
elif message in ['humid', 'humidity', 'h']:
55+
elif message in ["humid", "humidity", "h"]:
6356
response = "Humidity: %0.1f %%" % humid
64-
elif message in ['pres', 'pressure', 'p']:
57+
elif message in ["pres", "pressure", "p"]:
6558
response = "Pressure: %0.1f hPa" % pres
66-
elif message in ['status', 's']:
67-
response = "Temperature: {0:.2f}C\nHumidity: {1:.1f}% \
68-
Pressure: {2:.1f}hPa".format(temp, humid, pres)
69-
elif message in ['help']:
59+
elif message in ["status", "s"]:
60+
response = "Temperature: {0:.2f}C\nHumidity: {1:.1f}%Pressure: {2:.1f}hPa".format(
61+
temp, humid, pres
62+
)
63+
elif message in ["help"]:
7064
response = "I'm a SMS Sensor - txt me with a command:\
7165
TEMP - Read temperature\
7266
HUMID - Read humidity\
@@ -82,8 +76,3 @@
8276
if not fona.send_sms(int(sender), response):
8377
print("SMS Send Failed")
8478
print("SMS Sent!")
85-
86-
# Delete the original message
87-
if not fona.delete_sms(sms_slot):
88-
print("Could not delete SMS in slot", sms_slot)
89-
print("OK!")
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import board
2+
import displayio
3+
import adafruit_imageload
4+
5+
# from tilegame_assets.controls_helper import controls
6+
import ugame
7+
8+
display = board.DISPLAY
9+
player_loc = {"x": 4, "y": 3}
10+
11+
# Load the sprite sheet (bitmap)
12+
sprite_sheet, palette = adafruit_imageload.load(
13+
"tilegame_assets/castle_sprite_sheet.bmp",
14+
bitmap=displayio.Bitmap,
15+
palette=displayio.Palette,
16+
)
17+
18+
# Create the sprite TileGrid
19+
sprite = displayio.TileGrid(
20+
sprite_sheet,
21+
pixel_shader=palette,
22+
width=1,
23+
height=1,
24+
tile_width=16,
25+
tile_height=16,
26+
default_tile=0,
27+
)
28+
29+
# Create the castle TileGrid
30+
castle = displayio.TileGrid(
31+
sprite_sheet,
32+
pixel_shader=palette,
33+
width=10,
34+
height=8,
35+
tile_width=16,
36+
tile_height=16,
37+
)
38+
39+
# Create a Group to hold the sprite and add it
40+
sprite_group = displayio.Group()
41+
sprite_group.append(sprite)
42+
43+
# Create a Group to hold the castle and add it
44+
castle_group = displayio.Group(scale=1)
45+
castle_group.append(castle)
46+
47+
# Create a Group to hold the sprite and castle
48+
group = displayio.Group()
49+
50+
# Add the sprite and castle to the group
51+
group.append(castle_group)
52+
group.append(sprite_group)
53+
54+
# Castle tile assignments
55+
# corners
56+
castle[0, 0] = 3 # upper left
57+
castle[9, 0] = 5 # upper right
58+
castle[0, 7] = 9 # lower left
59+
castle[9, 7] = 11 # lower right
60+
# top / bottom walls
61+
for x in range(1, 9):
62+
castle[x, 0] = 4 # top
63+
castle[x, 7] = 10 # bottom
64+
# left/ right walls
65+
for y in range(1, 7):
66+
castle[0, y] = 6 # left
67+
castle[9, y] = 8 # right
68+
# floor
69+
for x in range(1, 9):
70+
for y in range(1, 7):
71+
castle[x, y] = 7 # floor
72+
73+
# put the sprite somewhere in the castle
74+
sprite.x = 16 * player_loc["x"]
75+
sprite.y = 16 * player_loc["y"]
76+
77+
# Add the Group to the Display
78+
display.show(group)
79+
80+
prev_btn_vals = ugame.buttons.get_pressed()
81+
82+
while True:
83+
cur_btn_vals = ugame.buttons.get_pressed()
84+
if not prev_btn_vals & ugame.K_UP and cur_btn_vals & ugame.K_UP:
85+
player_loc["y"] = max(1, player_loc["y"] - 1)
86+
if not prev_btn_vals & ugame.K_DOWN and cur_btn_vals & ugame.K_DOWN:
87+
player_loc["y"] = min(6, player_loc["y"] + 1)
88+
89+
if not prev_btn_vals & ugame.K_RIGHT and cur_btn_vals & ugame.K_RIGHT:
90+
player_loc["x"] = min(8, player_loc["x"] + 1)
91+
if not prev_btn_vals & ugame.K_LEFT and cur_btn_vals & ugame.K_LEFT:
92+
player_loc["x"] = max(1, player_loc["x"] - 1)
93+
94+
# update the the player sprite position
95+
sprite.x = 16 * player_loc["x"]
96+
sprite.y = 16 * player_loc["y"]
97+
98+
# update the previous values
99+
prev_btn_vals = cur_btn_vals
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import board
2+
import displayio
3+
import adafruit_imageload
4+
import ugame
5+
6+
display = board.DISPLAY
7+
player_loc = {"x": 4, "y": 3}
8+
9+
# Load the sprite sheet (bitmap)
10+
sprite_sheet, palette = adafruit_imageload.load(
11+
"tilegame_assets/castle_sprite_sheet_edited.bmp",
12+
bitmap=displayio.Bitmap,
13+
palette=displayio.Palette,
14+
)
15+
# make the color at 0 index transparent.
16+
palette.make_transparent(0)
17+
18+
# Create the sprite TileGrid
19+
sprite = displayio.TileGrid(
20+
sprite_sheet,
21+
pixel_shader=palette,
22+
width=1,
23+
height=1,
24+
tile_width=16,
25+
tile_height=16,
26+
default_tile=0,
27+
)
28+
29+
# Create the castle TileGrid
30+
castle = displayio.TileGrid(
31+
sprite_sheet,
32+
pixel_shader=palette,
33+
width=10,
34+
height=8,
35+
tile_width=16,
36+
tile_height=16,
37+
)
38+
39+
# Create a Group to hold the sprite and add it
40+
sprite_group = displayio.Group()
41+
sprite_group.append(sprite)
42+
43+
# Create a Group to hold the castle and add it
44+
castle_group = displayio.Group(scale=1)
45+
castle_group.append(castle)
46+
47+
# Create a Group to hold the sprite and castle
48+
group = displayio.Group()
49+
50+
# Add the sprite and castle to the group
51+
group.append(castle_group)
52+
group.append(sprite_group)
53+
54+
# Castle tile assignments
55+
# corners
56+
castle[0, 0] = 3 # upper left
57+
castle[9, 0] = 5 # upper right
58+
castle[0, 7] = 9 # lower left
59+
castle[9, 7] = 11 # lower right
60+
# top / bottom walls
61+
for x in range(1, 9):
62+
castle[x, 0] = 4 # top
63+
castle[x, 7] = 10 # bottom
64+
# left/ right walls
65+
for y in range(1, 7):
66+
castle[0, y] = 6 # left
67+
castle[9, y] = 8 # right
68+
# floor
69+
for x in range(1, 9):
70+
for y in range(1, 7):
71+
castle[x, y] = 7 # floor
72+
73+
# put the sprite somewhere in the castle
74+
sprite.x = 16 * player_loc["x"]
75+
sprite.y = 16 * player_loc["y"]
76+
77+
# Add the Group to the Display
78+
display.show(group)
79+
80+
prev_btn_vals = ugame.buttons.get_pressed()
81+
82+
while True:
83+
cur_btn_vals = ugame.buttons.get_pressed()
84+
if not prev_btn_vals & ugame.K_UP and cur_btn_vals & ugame.K_UP:
85+
player_loc["y"] = max(1, player_loc["y"] - 1)
86+
if not prev_btn_vals & ugame.K_DOWN and cur_btn_vals & ugame.K_DOWN:
87+
player_loc["y"] = min(6, player_loc["y"] + 1)
88+
89+
if not prev_btn_vals & ugame.K_RIGHT and cur_btn_vals & ugame.K_RIGHT:
90+
player_loc["x"] = min(8, player_loc["x"] + 1)
91+
if not prev_btn_vals & ugame.K_LEFT and cur_btn_vals & ugame.K_LEFT:
92+
player_loc["x"] = max(1, player_loc["x"] - 1)
93+
94+
# update the the player sprite position
95+
sprite.x = 16 * player_loc["x"]
96+
sprite.y = 16 * player_loc["y"]
97+
98+
# update the previous values
99+
prev_btn_vals = cur_btn_vals
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import board
2+
import displayio
3+
import adafruit_imageload
4+
5+
display = board.DISPLAY
6+
7+
# Load the sprite sheet (bitmap)
8+
sprite_sheet, palette = adafruit_imageload.load(
9+
"tilegame_assets/castle_sprite_sheet.bmp",
10+
bitmap=displayio.Bitmap,
11+
palette=displayio.Palette,
12+
)
13+
14+
# Create the sprite TileGrid
15+
sprite = displayio.TileGrid(
16+
sprite_sheet,
17+
pixel_shader=palette,
18+
width=1,
19+
height=1,
20+
tile_width=16,
21+
tile_height=16,
22+
default_tile=0,
23+
)
24+
25+
# Create the castle TileGrid
26+
castle = displayio.TileGrid(
27+
sprite_sheet,
28+
pixel_shader=palette,
29+
width=10,
30+
height=8,
31+
tile_width=16,
32+
tile_height=16,
33+
)
34+
35+
# Create a Group to hold the sprite and add it
36+
sprite_group = displayio.Group()
37+
sprite_group.append(sprite)
38+
39+
# Create a Group to hold the castle and add it
40+
castle_group = displayio.Group(scale=1)
41+
castle_group.append(castle)
42+
43+
# Create a Group to hold the sprite and castle
44+
group = displayio.Group()
45+
46+
# Add the sprite and castle to the group
47+
group.append(castle_group)
48+
group.append(sprite_group)
49+
50+
# Castle tile assignments
51+
# corners
52+
castle[0, 0] = 3 # upper left
53+
castle[9, 0] = 5 # upper right
54+
castle[0, 7] = 9 # lower left
55+
castle[9, 7] = 11 # lower right
56+
# top / bottom walls
57+
for x in range(1, 9):
58+
castle[x, 0] = 4 # top
59+
castle[x, 7] = 10 # bottom
60+
# left/ right walls
61+
for y in range(1, 7):
62+
castle[0, y] = 6 # left
63+
castle[9, y] = 8 # right
64+
# floor
65+
for x in range(1, 9):
66+
for y in range(1, 7):
67+
castle[x, y] = 7 # floor
68+
69+
# put the sprite somewhere in the castle
70+
sprite.x = 16 * 4
71+
sprite.y = 16 * 3
72+
73+
# Add the Group to the Display
74+
display.show(group)
75+
while True:
76+
pass

0 commit comments

Comments
 (0)