aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--elegoo/elegoo.ino4
-rw-r--r--fsm.go5
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
}