Skip to content

Commit 2dffb82

Browse files
refactor for learning guide
1 parent 7ef5e1c commit 2dffb82

File tree

4 files changed

+5
-8
lines changed

4 files changed

+5
-8
lines changed

examples/clue_scale_bkg.bmp

-225 KB
Binary file not shown.

examples/clue_scale_code.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,13 @@
2929
SCALE_NAME_1 = "COFFEE" # 6 characters maximum
3030
SCALE_NAME_2 = "SCALE" # 6 characters maximum
3131

32-
min_gr = (MAX_GR // 5) * -1 # Calculated minimum display value
33-
3432
"""Enter the calibration ratio for the individual load cell in-use. The ratio is
3533
composed of the reference weight in grams divided by the raw reading. For
3634
example, a raw reading of 215300 for a 100 gram weight results in a calibration
3735
ratio of 100 / 215300. Use the clue_scale_single_calibrate method to obtain the
3836
raw value.
3937
FYI: A US dime coin weighs 2.268 ounces or 64.3 grams."""
40-
CALIB_RATIO_1 = 100 / 215300 # load cell serial#4540-02
38+
CALIB_RATIO = 100 / 215300 # load cell serial#4540-02
4139

4240
# Instantiate the Sensor and Display
4341
nau7802 = NAU7802(board.I2C(), address=0x2A, active_channels=1)
@@ -154,12 +152,13 @@ def read(samples=100):
154152

155153
# Read the raw scale value and scale for grams and ounces
156154
value = read(SAMPLE_AVG)
157-
mass_grams = round(value * CALIB_RATIO_1, 1)
155+
mass_grams = round(value * CALIB_RATIO, 1)
158156
mass_ounces = round(mass_grams * 0.03527, 2)
159157
grams_value.text = f"{mass_grams:5.1f}"
160158
ounces_value.text = f"{mass_ounces:5.2f}"
161159

162160
# Reposition the indicator bubble based on grams value
161+
min_gr = (MAX_GR // 5) * -1 # Minimum display value
163162
bubble.y = int(map_range(mass_grams, min_gr, MAX_GR, 240, 0)) - 10
164163
if mass_grams > MAX_GR or mass_grams < min_gr:
165164
bubble.fill = clue.RED

examples/dual_clue_scale_code.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
CHAN_1_LABEL = "SHOT" # 6 characters maximum
2828
CHAN_2_LABEL = "BEANS" # 6 characters maximum
2929

30-
min_gr = (MAX_GR // 5) * -1 # Calculated minimum display value
31-
3230
"""Enter the calibration ratio for the individual load cell in-use. The ratio is
3331
composed of the reference weight in grams divided by the raw reading. For
3432
example, a raw reading of 215300 for a 100 gram weight results in a calibration
@@ -167,6 +165,7 @@ def read(samples=100):
167165
chan_1_mass_oz = round(chan_1_mass_gr * 0.03527, 2)
168166
chan_1_value.text = f"{chan_1_mass_gr:5.1f}"
169167

168+
min_gr = (MAX_GR // 5) * -1 # Minimum display value
170169
chan_1_bubble.y = int(map_range(chan_1_mass_gr, min_gr, MAX_GR, 240, 0)) - 8
171170
if chan_1_mass_gr > MAX_GR or chan_1_mass_gr < min_gr:
172171
chan_1_bubble.fill = clue.RED

examples/dual_clue_scale_mux_code.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
SENSOR_1_LABEL = "SHOT" # 6 characters maximum
2929
SENSOR_2_LABEL = "BEANS" # 6 characters maximum
3030

31-
min_gr = (MAX_GR // 5) * -1 # Calculated minimum display value
32-
3331
"""Enter the calibration ratio for the individual load cell in-use. The ratio is
3432
composed of the reference weight in grams divided by the raw reading. For
3533
example, a raw reading of 215300 for a 100 gram weight results in a calibration
@@ -183,6 +181,7 @@ def read(sensor=1, samples=100):
183181
sensor_1_mass_oz = round(sensor_1_mass_gr * 0.03527, 2)
184182
sensor_1_value.text = f"{sensor_1_mass_gr:5.1f}"
185183

184+
min_gr = (MAX_GR // 5) * -1 # Minimum display value
186185
sensor_1_bubble.y = int(map_range(sensor_1_mass_gr, min_gr, MAX_GR, 240, 0)) - 8
187186
if sensor_1_mass_gr > MAX_GR or sensor_1_mass_gr < min_gr:
188187
sensor_1_bubble.fill = clue.RED

0 commit comments

Comments
 (0)