Skip to content

Commit

Permalink
ζŽ’η‰ˆ
Browse files Browse the repository at this point in the history
  • Loading branch information
junhuanchen committed Nov 6, 2018
1 parent 026ae49 commit 526ad7c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions 10.microbit/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, pin):

def read(self):
self.old = self.new
self.new = self.adc.read()/4.095
self.new = self.adc.read() / 4.095
return int(self.new)

# result > 0 to state up, < 0 to state down.
Expand All @@ -23,7 +23,7 @@ def get_state(self):
return 0 if abs(tmp) < self.eliminate else tmp

def calibrate(self):
self.eliminate = 2+self.read() / Intensity.dither
self.eliminate = 2 + self.read() / Intensity.dither


class Gesture(object):
Expand All @@ -43,7 +43,9 @@ def get_gesture(self, delay=25):
sleep_ms(delay)
self.get_brightness()
l_state, r_state = self.l.get_state(), self.r.get_state()

result = []

if self.l_state == Gesture.idle and r_state > 0 and self.r.new-self.l.new > self.l.eliminate:
self.l_count = 0
self.l_state = Gesture.ing
Expand Down Expand Up @@ -77,9 +79,9 @@ def get_gesture(self, delay=25):
result.append('right')

if l_state == 0 and r_state == 0 and self.l_state == Gesture.idle and self.r_state == Gesture.idle:
self.updata +=1
if self.updata>20:
self.updata=0
self.updata += 1
if self.updata > 20:
self.updata = 0
self.l.calibrate()
self.r.calibrate()

Expand All @@ -103,7 +105,7 @@ def unit_test():
res = g.get_gesture()
if res != None:
print(res)
count = 1+count
count = 1 + count
print(count)


Expand Down

0 comments on commit 526ad7c

Please sign in to comment.