"""With no screen and no keypad, we have to make do with the buttons and LEDs.
The *ui_utils* module gives you the ability to enter data at program run-time.
This can reduce the number of times you have to edit and re-download your program.
This is especially handy if you are running your CodeBot untethered.
Attributes:
UI_BUTTON_NONE (int): value used to represent NO BUTTON is pressed
UI_BUTTON_0 (int) : value used to represent BTN-0 is pressed
UI_BUTTON_1 (int) : value used to represent BTN-1 is pressed
UI_BUTTON_BOTH (int) : value used to represent BOTH buttons are pressed
Treating "both buttons are pressed" as a special case gives us a virtual 3rd button.
"""
import botcore as cb
#import devbotcore as cb
import time
UI_BUTTON_NONE = 0x00
UI_BUTTON_0 = 0x01
UI_BUTTON_1 = 0x02
UI_BUTTON_BOTH = 0x03
[docs]def tweak_parameter(initial_value):
"""Allows a value to be adjusted, or kept as-is:
Press BTN-1 to raise the value.
Press BTN-0 to lower the value.
Press BOTH buttons at the same time to lock-in your choice.
Flashes the final value on the LEDs so you can tell what you entered.
Args:
initial_value (int): the value to start at.
"""
value = initial_value
cb.leds.user(value)
done = False
while not done:
button = get_button()
if button == UI_BUTTON_BOTH:
done = True
elif button == UI_BUTTON_1:
if value < 255:
value += 1
elif button == UI_BUTTON_0:
if value > 0:
value -= 1
cb.leds.user(value)
count = 3
while count:
count -= 1
cb.leds.user(0)
time.sleep(0.5)
cb.leds.user(value)
time.sleep(0.5)
cb.leds.user(0)
time.sleep(0.5)
return value