Python pyb.millis() Examples
The following are 11
code examples of pyb.millis().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyb
, or try the search function
.
Example #1
Source File: drumseq.py From micropython-stm-lib with MIT License | 6 votes |
def play(self, pattern, kit=None): # channel volume self.midiout.control_change(10, self.volume, ch=self.channel) self.activate_drumkit(kit) # give MIDI instrument some time to load drumkit delay(200) try: while True: last_tick = millis() pattern.playstep(self.midiout, self.channel) timetowait = max(0, self.mpt - (millis() - last_tick)) if timetowait > 0: delay(int(timetowait)) finally: # all sound off self.midiout.control_change(120, 0, ch=self.channel)
Example #2
Source File: pid.py From flight_controller with GNU General Public License v3.0 | 6 votes |
def get_pid(self, error, scaler): tnow = millis() dt = tnow - self._last_t output = 0 if self._last_t == 0 or dt > 1000: dt = 0 self.reset_I() self._last_t = tnow delta_time = float(dt) / float(1000) output += error * self._kp if abs(self._kd) > 0 and dt > 0: if isnan(self._last_derivative): derivative = 0 self._last_derivative = 0 else: derivative = (error - self._last_error) / delta_time derivative = self._last_derivative + \ ((delta_time / (self._RC + delta_time)) * \ (derivative - self._last_derivative)) self._last_error = error self._last_derivative = derivative output += self._kd * derivative output *= scaler if abs(self._ki) > 0 and dt > 0: self._integrator += (error * self._ki) * scaler * delta_time if self._integrator < -self._imax: self._integrator = -self._imax elif self._integrator > self._imax: self._integrator = self._imax output += self._integrator return output
Example #3
Source File: Main_perf.py From uPyIDE with GNU General Public License v3.0 | 5 votes |
def performanceTest(): d = 10000 print("start. Wait for %d milis" % d) millis = pyb.millis endTime = millis() + d count = 0 while millis() < endTime: count += 1 print("Count: ", count)
Example #4
Source File: pid.py From OpenMV-Pan-Tilt with MIT License | 5 votes |
def get_pid(self, error, scaler): tnow = millis() dt = tnow - self._last_t output = 0 if self._last_t == 0 or dt > 1000: dt = 0 self.reset_I() self._last_t = tnow delta_time = float(dt) / float(1000) output += error * self._kp if abs(self._kd) > 0 and dt > 0: if isnan(self._last_derivative): derivative = 0 self._last_derivative = 0 else: derivative = (error - self._last_error) / delta_time derivative = self._last_derivative + \ ((delta_time / (self._RC + delta_time)) * \ (derivative - self._last_derivative)) self._last_error = error self._last_derivative = derivative output += self._kd * derivative output *= scaler if abs(self._ki) > 0 and dt > 0: self._integrator += (error * self._ki) * scaler * delta_time if self._integrator < -self._imax: self._integrator = -self._imax elif self._integrator > self._imax: self._integrator = self._imax output += self._integrator return output
Example #5
Source File: epdpart.py From micropython-epaper with Apache License 2.0 | 5 votes |
def frame_data_repeat(self, stage, use_old): self.asm_data[0] = addressof(self.image) self.asm_data[1] = addressof(self.image_old) if use_old else 0 start = pyb.millis() count = 0 while True: self.frame_data(stage) count +=1 if pyb.elapsed_millis(start) > self.factored_stage_time: break if self.verbose: print('frame_data_repeat count = {}'.format(count))
Example #6
Source File: epdpart.py From micropython-epaper with Apache License 2.0 | 5 votes |
def frame_fixed_repeat(self, fixed_value, stage): start = pyb.millis() count = 0 while True: self.frame_fixed(fixed_value, stage) count +=1 if pyb.elapsed_millis(start) > self.factored_stage_time: break if self.verbose: print('frame_fixed_repeat count = {}'.format(count))
Example #7
Source File: epd.py From micropython-epaper with Apache License 2.0 | 5 votes |
def _frame_fixed_timed(self, fixed_value, stage_time): t_start = pyb.millis() t_elapsed = -1 while t_elapsed < stage_time: for line in range(LINES_PER_DISPLAY -1, -1, -1): self._line_fixed(line, fixed_value, set_voltage_limit = False) t_elapsed = pyb.elapsed_millis(t_start)
Example #8
Source File: elapsed.py From upy-examples with MIT License | 5 votes |
def blink_millis(): start = pyb.millis() led.on() while pyb.elapsed_millis(start) < 100: pass led.off() while pyb.elapsed_millis(start) < 200: pass led.on() while pyb.elapsed_millis(start) < 300: pass led.off() while pyb.elapsed_millis(start) < 1000: pass
Example #9
Source File: counter_perf.py From upy-examples with MIT License | 5 votes |
def sk(): count = 0 millis = pyb.millis print('start') kon = millis() + 1000 while millis() < kon: count += 1 print('normal', count)
Example #10
Source File: counter_perf.py From upy-examples with MIT License | 5 votes |
def skn(): count = 0 millis = pyb.millis print('start') kon = millis() + 1000 while millis() < kon: count += 1 print("native", count)
Example #11
Source File: elapsed.py From upy-examples with MIT License | 5 votes |
def blink_millis(): start = pyb.millis() led.on() while pyb.elapsed_millis(start) < 100: pass led.off() while pyb.elapsed_millis(start) < 200: pass led.on() while pyb.elapsed_millis(start) < 300: pass led.off() while pyb.elapsed_millis(start) < 1000: pass