@@ -3,8 +3,9 @@ package easystepper // import "tinygo.org/x/drivers/easystepper"
3
3
4
4
import (
5
5
"errors"
6
- "machine"
7
6
"time"
7
+
8
+ "tinygo.org/x/drivers"
8
9
)
9
10
10
11
// StepMode determines the coil sequence used to perform a single step
@@ -33,7 +34,7 @@ func (sm StepMode) stepCount() uint {
33
34
// DeviceConfig contains the configuration data for a single easystepper driver
34
35
type DeviceConfig struct {
35
36
// Pin1 ... Pin4 determines the pins to configure and use for the device
36
- Pin1 , Pin2 , Pin3 , Pin4 machine .Pin
37
+ Pin1 , Pin2 , Pin3 , Pin4 drivers .Pin
37
38
// StepCount is the number of steps required to perform a full revolution of the stepper motor
38
39
StepCount uint
39
40
// RPM determines the speed of the stepper motor in 'Revolutions per Minute'
@@ -46,12 +47,12 @@ type DeviceConfig struct {
46
47
type DualDeviceConfig struct {
47
48
DeviceConfig
48
49
// Pin5 ... Pin8 determines the pins to configure and use for the second device
49
- Pin5 , Pin6 , Pin7 , Pin8 machine .Pin
50
+ Pin5 , Pin6 , Pin7 , Pin8 drivers .Pin
50
51
}
51
52
52
53
// Device holds the pins and the delay between steps
53
54
type Device struct {
54
- pins [4 ]machine .Pin
55
+ pins [4 ]drivers .Pin
55
56
stepDelay time.Duration
56
57
stepNumber uint8
57
58
stepMode StepMode
@@ -68,17 +69,15 @@ func New(config DeviceConfig) (*Device, error) {
68
69
return nil , errors .New ("config.StepCount and config.RPM must be > 0" )
69
70
}
70
71
return & Device {
71
- pins : [4 ]machine .Pin {config .Pin1 , config .Pin2 , config .Pin3 , config .Pin4 },
72
+ pins : [4 ]drivers .Pin {config .Pin1 , config .Pin2 , config .Pin3 , config .Pin4 },
72
73
stepDelay : time .Second * 60 / time .Duration ((config .StepCount * config .RPM )),
73
74
stepMode : config .Mode ,
74
75
}, nil
75
76
}
76
77
77
- // Configure configures the pins of the Device
78
+ // Configure does nothing, as it assumes that the pins of the Device have already
79
+ // been configured by the user as outputs.
78
80
func (d * Device ) Configure () {
79
- for _ , pin := range d .pins {
80
- pin .Configure (machine.PinConfig {Mode : machine .PinOutput })
81
- }
82
81
}
83
82
84
83
// NewDual returns a new dual easystepper driver given 8 pins, number of steps and rpm
0 commit comments