@@ -35,11 +35,11 @@ Output should look like this:
35
35
Modified 14 Dec 2022 by Joe Brendler
36
36
*/
37
37
38
- // #include <Arduino.h>
38
+ #include < Arduino.h>
39
39
#include < Stepper.h>
40
40
41
- # define pot A0
42
- # define pushbutton 37
41
+ const int pot = 0 ; // A0
42
+ const int pushbutton = 2 ; // D2, int0
43
43
44
44
const int stepsPerRevolution = 200 ; // change this to fit the number of steps per revolution for your motor
45
45
long speed = 50 ; // analog input reading (in rpm)
@@ -58,7 +58,8 @@ Stepper myStepper(stepsPerRevolution, 17, 18, 19);
58
58
/* ------------------------------------------------------------------------------
59
59
handle_button_interrupt() - set flag and call stepper interrupt method
60
60
------------------------------------------------------------------------------*/
61
- void IRAM_ATTR handle_button_interrupt ()
61
+ // void IRAM_ATTR handle_button_interrupt()
62
+ void handle_button_interrupt ()
62
63
{
63
64
buttonPress.PRESSED = true ;
64
65
myStepper.interrupt (); // method sets a flag
@@ -74,7 +75,7 @@ void setup()
74
75
75
76
// Configure function pushbutton interrupt pin
76
77
Serial.print (" config pushbutton" );
77
- pinMode (buttonPress.PIN , INPUT_PULLDOWN );
78
+ pinMode (buttonPress.PIN , INPUT );
78
79
Serial.println (" ==> Done" );
79
80
Serial.print (" Attach interrupt... " );
80
81
attachInterrupt (buttonPress.PIN , handle_button_interrupt, FALLING);
@@ -92,7 +93,8 @@ void loop()
92
93
// read speed from 12-bit ADC input (map 1-100; stepper doesn't like speed=0)
93
94
speed = (long )(map (analogRead (pot), 0 , 4095 , 1 , 100 ));
94
95
myStepper.setSpeed (speed);
95
- Serial.printf (" clockwise, speed: %d " , speed);
96
+ Serial.print (" clockwise, speed: " );
97
+ Serial.print (speed);
96
98
// step one revolution in one direction:
97
99
myStepper.step (stepsPerRevolution);
98
100
if (buttonPress.PRESSED )
@@ -109,7 +111,8 @@ void loop()
109
111
// read speed from 12-bit ADC input (map 1-100; stepper doesn't like speed=0)
110
112
speed = (long )(map (analogRead (pot), 0 , 4095 , 1 , 100 ));
111
113
myStepper.setSpeed (speed);
112
- Serial.printf (" counterclockwise, speed: %d " , speed);
114
+ Serial.print (" clockwise, speed: " );
115
+ Serial.print (speed);
113
116
// step one revolution in the other direction:
114
117
myStepper.step (-stepsPerRevolution);
115
118
if (buttonPress.PRESSED )
0 commit comments