From ec5197a8071c7db355de30b1f77b66c64beabae7 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 10 Dec 2017 20:49:37 +0100 Subject: ... --- elegoo/elegoo.ino | 4 ++-- fsm.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/elegoo/elegoo.ino b/elegoo/elegoo.ino index c0a151a..62d7d62 100644 --- a/elegoo/elegoo.ino +++ b/elegoo/elegoo.ino @@ -36,7 +36,7 @@ void motor(int e, int a, int b, int v) { #define motorR(v) motor(ENA, IN1, IN2, v) #define motorL(v) motor(ENB, IN3, IN4, v) -int distance() { +int readDistance() { digitalWrite(Trig, LOW); delayMicroseconds(2); digitalWrite(Trig, HIGH); @@ -78,7 +78,7 @@ void events() { Events evt = Events_init_zero; - evt.Distance = distance(); + evt.Distance = readDistance(); evt.has_Distance = evt.Distance > 0; evt.SensorR = digitalRead(SR); diff --git a/fsm.go b/fsm.go index 3a65198..3e3cb6e 100644 --- a/fsm.go +++ b/fsm.go @@ -53,12 +53,13 @@ func (f *FSM) Start() { } func (f *FSM) initalState() stateFn { - f.command <- &Command{Direction: 85} + f.command <- &Command{Direction: 90} return f.readDistance } func (f *FSM) readDistance() stateFn { ev := <-f.events + log.Println(ev) if ev.Distance < 20 { return f.stop } @@ -72,5 +73,5 @@ func (f *FSM) moveAhead() stateFn { func (f *FSM) stop() stateFn { f.command <- &Command{Stop: true} - return nil + return f.readDistance } -- cgit v1.2.3