Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conecube mode is alternating white & conecube color #10

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 47 additions & 116 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
import neopixel
from rainbowio import colorwheel


from microcontroller import watchdog as w
from watchdog import WatchDogMode
w.timeout=1.0
w.mode = WatchDogMode.RESET
'''
#############################################
######
###### INPUT MAP
######
###### Alliance: [pin7]
###### Alliance: 1 = blue, 0 = red
######
######
###### Input mapping for light display:
###### [pin13][pin12][pin11][pin10][pin9]
######
Expand All @@ -28,14 +27,11 @@
###### 00011 3 cube mode display_Cube
###### 00100 4 cone acq. blinkingCone
###### 00101 5 cube acq. blinkingCube
###### 00110 6 cone mode display_Cone
######
######
######
###### 00110 6 cone mode display_Cone
#############################################

#############################################
###### setup board output & neopixel light strip objects
###### setup vars
#############################################
'''
pixel_pin = board.D5
Expand All @@ -48,49 +44,38 @@

conecube_length = 10
current_mode_length = 20-conecube_length

movingRainbow = 0
current_time = time.time()

mode = 31

'''
#############################################
###### setup pins for input
###### setup input
#############################################
'''

#pin7
pin_conecube = DigitalInOut(board.D7)
pin_conecube.direction = Direction.INPUT
pin_conecube.pull = Pull.DOWN

#pin9
pin9 = DigitalInOut(board.D9)
pin9.direction = Direction.INPUT
pin9.pull = Pull.DOWN

#pin10
pin10 = DigitalInOut(board.D10)
pin10.direction = Direction.INPUT
pin10.pull = Pull.DOWN

#pin11
pin11 = DigitalInOut(board.D11)
pin11.direction = Direction.INPUT
pin11.pull = Pull.DOWN

#pin12
pin12 = DigitalInOut(board.D12)
pin12.direction = Direction.INPUT
pin12.pull = Pull.DOWN

#pin13
pin13 = DigitalInOut(board.D13)
pin13.direction = Direction.INPUT
pin13.pull = Pull.DOWN



'''
#############################################
###### color display functions
Expand Down Expand Up @@ -138,44 +123,32 @@ def disabled():
pixels.show()
wait_and_check(wait)

def disabled_with_auto():
def disabled_with_auto(color):
for i in range(num_pixels):
pixels[i]=(20, 50, 20)
pixels[i]=color
for countdown in range(steps, 1, -1):
pixels.brightness = countdown/steps
pixels.show()
wait_and_check(wait)

for countup in range(1, steps, 1):
pixels.brightness = countup/steps
pixels.show()
wait_and_check(wait)

def blinkingCube():
for cube in range(current_mode_length):
pixels[cube]=(145, 0, 255)
pixels.show()
wait_and_check(0.3)
for cube in range(current_mode_length):
pixels[cube]=(0, 0, 0)
pixels.show()
wait_and_check(0.2)

def blinkingCone():
for cone in range(current_mode_length):
pixels[cone]=(255, 165, 0)
pixels.show()
wait_and_check(0.3)
for cone in range(current_mode_length):
pixels[cone]=(0, 0, 0)
pixels.show()
wait_and_check(0.2)

def display_cone_cube(color):
for i in range(20-conecube_length, 20, 1):
pixels[i]=color


global current_time
if time.time() - current_time < 0.25:
return
if current_time % 2 == 0:
for i in range(20-conecube_length, 20, 1):
if i >= (20-conecube_length)+conecube_length/2: pixels[i]=color
else: pixels[i]=(255,255,255)
else:
for i in range(20-conecube_length, 20, 1):
if i >= (20-conecube_length)+conecube_length/2: pixels[i]=(255,255,255)
else: pixels[i]=color
current_time = time.time()

def moving_rainbow(switch):
global movingRainbow
length = 0
Expand All @@ -192,24 +165,8 @@ def moving_rainbow(switch):
pixels.show()
movingRainbow = movingRainbow+1

'''
#############################################
###### get current input from robot
#############################################
'''

def read_current_mode():
temp = int(pin9.value)
temp1 = int(pin10.value)<<1
temp2 = int(pin11.value)<<2
temp3 = int(pin12.value)<<3
temp4 = int(pin13.value)<<4
return (temp+temp1+temp2+temp3+temp4)

'''
#########################################################
####### get current input from robot for cone/cube
'''
return int(pin9.value)+int(pin10.value<<1)+int(pin11.value<<2)+int(pin12.value<<3)+int(pin13.value<<4) #(temp+temp1+temp2+temp3+temp4)

def update_conecube_mode():
if pin_conecube.value == 1:
Expand All @@ -222,22 +179,33 @@ class ModeChangedException(Exception):
pass

def wait_and_check(durationS):
w.feed()
if mode == read_current_mode():
time.sleep(durationS)
else:
raise ModeChangedException("Mode changed")

#############################################
###### main loop
#############################################
def unknown(len):
for i in range(len):
pixels[i]=(0, 255, 0)
for countdown in range(steps, 1, -1):
pixels.brightness = countdown/steps
pixels.show()
wait_and_check(wait)
for countup in range(1, steps, 1):
pixels.brightness = countup/steps
pixels.show()
wait_and_check(wait)

def display_Cone():
for i in range(15, 20, 1):
pixels[i]=(255, 165, 0)
pixels.show()

def main():
global mode
# Read mode and alliance from pins
mode = read_current_mode()

try:
#Select display option
if mode == 31:
no_code()
elif mode == 1:
Expand All @@ -247,52 +215,15 @@ def main():
elif mode == 3:
moving_rainbow(False)
elif mode == 4:
disabled_with_auto()
elif mode == 5: #arm in position
disabled_with_auto((20, 50, 20))
elif mode == 5:
moving_rainbow(True)
elif mode == 6:
disabled_with_auto((0, 150, 0))
else:
no_code()
unknown(min(mode,20))
except ModeChangedException:
# Mode changed, restart loop
pass

while True:
main()


####### EXTRAS ########

'''def lowBattery():
for lowBattery in range(20):
pixels[lowBattery]=(0, 255, 0)
pixels.show()
wait_and_check(5/count)
for lowBattery in range(20):
pixels[lowBattery]=(240, 70, 0)
pixels.show()
wait_and_check(1)

if count < 4:
for lowBattery in range(20):
pixels[lowBattery]=(0, 255, 0)
pixels.show()
wait_and_check(5/count)
for lowBattery in range(20):
pixels[lowBattery]=(240, 70, 0)
pixels.show()
wait_and_check(1)

elif count >= 4 and count >= 8:
for lowBattery in range(20):
pixels[lowBattery]=(240, 70, 0)
pixels.show()
wait_and_check(5/(count-3))
for lowBattery in range(20):
pixels[lowBattery]=(255, 0, 0)
pixels.show()
wait_and_check(1)

else:
pixels[lowBattery]=(255, 0, 0)'''


main()
3 changes: 3 additions & 0 deletions safemode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import microcontroller

microcontroller.reset()