Ledka blikne každých 10 sekund, kdy se posílá signál pro krokový motor, který se správně pootočí. Jenže další část programu nefunguje. GPIO 20 a 21 by mělo být podle programu HIGH, ale je na zemi a tlačítka nefungují.
Mohla by mě nějaká dobrá duše poradit, jak to rozběhat celé?
# micropython program for the hollow-clock4
# https://www.thingiverse.com/thing:5636482
# for the rasperry pi pico
# V1.1 01.05.2023
# modified software based on pico sw from hollow clock2 author macke01
# (https://www.thingiverse.com/thing:4840471)
# timing modified for Hollow Clock 4
# simplified time setting by addition of slow/fast forward and backward time set buttons
# simplified code, time base adjustment found unecessary with pi pico cpu clock
# reordered I/O assignment
# To syncronize hands - set hour and minute hands to 12 oclock by adjusting the minute & hour gears
# then place into base and adjust to correct time with time setting buttons
# If clock runs backwards, jumper Pi Pico pins 32 - 33 (GPIO27 - GND)
import utime
from machine import Pin
pin25=Pin(25,Pin.OUT)
pin25.value(0)
seq = [
[ 0, 1, 1, 0],
[ 0, 0, 1, 0],
[ 0, 0, 1, 1],
[ 0, 0, 0, 1],
[ 1, 0, 0, 1],
[ 1, 0, 0, 0],
[ 1, 1, 0, 0],
[ 0, 1, 0, 0]
]
class global_values:
# Constants
STEPS_PER_15MINUTES = 7680 # steps of a single revolution of motor gains 15 min.
STEPS_PER_MINUTE = int(STEPS_PER_15MINUTES/15)
STEPS_PER_5MINUTES = int(STEPS_PER_15MINUTES/3)
STEPS_PER_HOUR = STEPS_PER_15MINUTES * 4
def __init__(self):
# define and init move constants
self.STEPS_PER_MOVE = 32 # 32 steps per move
self.MOVES_PER_HOUR = self.STEPS_PER_15MINUTES * 4 / self.STEPS_PER_MOVE
self.PAUSE_BEWEEN_MOVES_MSEC = 60000*60 / self.MOVES_PER_HOUR
self.next_msec = utime.ticks_ms() + self.PAUSE_BEWEEN_MOVES_MSEC
# define and init variables
self.last_move_msec = utime.ticks_ms()
self.delaytime = 20 # wait between phases of stepper = smoothness
self.direction = 0 # direction of movement
self.prev_sec_msec = utime.ticks_ms()
def steps_per_move(self, steps):
# sets values depending on the steps per move
n = int(steps)
self.STEPS_PER_MOVE = n
self.MOVES_PER_HOUR = self.STEPS_PER_15MINUTES * 4 / self.STEPS_PER_MOVE
self.PAUSE_BEWEEN_MOVES_MSEC = 60000*60 / self.MOVES_PER_HOUR
G=global_values()
# pins assignment
pin1 = Pin(6,Pin.OUT) # Pico GPIO6 (Pin 9) connected to stepper control Pin In1
pin2 = Pin(7,Pin.OUT) # Pico GPIO7 (Pin 10) connected to stepper control Pin In2
pin3 = Pin(8,Pin.OUT) # Pico GPIO8 (Pin 11) connected to stepper control Pin In3
pin4 = Pin(9,Pin.OUT) # Pico GPIO9 (Pin 12) connected to stepper control Pin In4
# pins cause action when pulled down
pin_ffwd = Pin(20,Pin.IN, Pin.PULL_UP) # time set button fast forward GPIO20 (Pin 26)
pin_fbwd = Pin(21,Pin.IN, Pin.PULL_UP) # time set button fast backward GPIO21 (Pin 27)
pin_toggle_dir = Pin(27,Pin.IN, Pin.PULL_UP) # change clock run direction GPIO27 (Pin 32)
# phase and direction definition
pins_fwd = [pin1,pin2,pin3,pin4]
pins_bwd = [pin4,pin3,pin2,pin1]
pins_dir = [pins_fwd,pins_bwd]
pins = pins_dir[G.direction] #pins = [pin4,pin3,pin2,pin1] for forward movement
steps = [
[pin1],
[pin1,pin2],
[pin2],
[pin2,pin3],
[pin3],
[pin3,pin4],
[pin4],
[pin4,pin1],
]
def toggle_dir():
global pins, pins_dir
G.direction = (G.direction + 1) % 2
pins = pins_dir[G.direction]
def move(steps):
global pins
phase = 0
for j in range(steps):
phase = (phase + 1) % 8
for i in range(4):
pins.value(seq[phase])
pin25.value(seq[phase]) # Pico Led flashing.
utime.sleep_ms(G.delaytime)
# power cut
for i in range (4):
pins.value(0)
pin25.value(0) # Pico led off
# reverse stepper direction if needed - jumper pins 32 -33 on pico
if pin_toggle_dir.value() == 1:
toggle_dir()
while True:
# time set routine
fwd_flag = True # by default forward direction
t_button = utime.ticks_ms() # capture initial time to determine setting button press duration
while (pin_ffwd.value() ^ pin_fbwd.value()): # if only one button pushed
if (utime.ticks_ms() - t_button) < 500: # button press less than 500 ms
G.delaytime = 5 # then semi fast rotation
else:
G.delaytime = 1 # very fast rotation
# by default move forward continously as long as a setting button is pushed
# otherwise check fast backward button
if pin_fbwd.value() == 0: # move backward continously as long as pin is pulled down
if fwd_flag:
toggle_dir() # reverse direction
fwd_flag = False # flag reverse direction
move(20)
if not (fwd_flag): # if previous command reverse direction
toggle_dir() # then restore
G.delaytime = 20 # resume
#main clock timing code
msec = utime.ticks_ms()
timediff = utime.ticks_diff(msec, G.last_move_msec)
# utime.ticks_diff cares about wrapping of msec values internally
# so we must not care about value wrapping
if timediff > G.PAUSE_BEWEEN_MOVES_MSEC:
# time since last move has passed
move(G.STEPS_PER_MOVE)
# set pause until next move
G.last_move_msec = utime.ticks_add(G.last_move_msec, int(G.PAUSE_BEWEEN_MOVES_MSEC))