@@ -35,11 +35,11 @@ Output should look like this:
3535 Modified 14 Dec 2022 by Joe Brendler
3636 */
3737
38- // #include <Arduino.h>
38+ #include < Arduino.h>
3939#include < Stepper.h>
4040
41- # define pot A0
42- # define pushbutton 37
41+ const int pot = 0 ; // A0
42+ const int pushbutton = 2 ; // D2, int0
4343
4444const int stepsPerRevolution = 200 ; // change this to fit the number of steps per revolution for your motor
4545long speed = 50 ; // analog input reading (in rpm)
@@ -58,7 +58,8 @@ Stepper myStepper(stepsPerRevolution, 17, 18, 19);
5858/* ------------------------------------------------------------------------------
5959 handle_button_interrupt() - set flag and call stepper interrupt method
6060 ------------------------------------------------------------------------------*/
61- void IRAM_ATTR handle_button_interrupt ()
61+ // void IRAM_ATTR handle_button_interrupt()
62+ void handle_button_interrupt ()
6263{
6364 buttonPress.PRESSED = true ;
6465 myStepper.interrupt (); // method sets a flag
@@ -74,7 +75,7 @@ void setup()
7475
7576 // Configure function pushbutton interrupt pin
7677 Serial.print (" config pushbutton" );
77- pinMode (buttonPress.PIN , INPUT_PULLDOWN );
78+ pinMode (buttonPress.PIN , INPUT );
7879 Serial.println (" ==> Done" );
7980 Serial.print (" Attach interrupt... " );
8081 attachInterrupt (buttonPress.PIN , handle_button_interrupt, FALLING);
@@ -92,7 +93,8 @@ void loop()
9293 // read speed from 12-bit ADC input (map 1-100; stepper doesn't like speed=0)
9394 speed = (long )(map (analogRead (pot), 0 , 4095 , 1 , 100 ));
9495 myStepper.setSpeed (speed);
95- Serial.printf (" clockwise, speed: %d " , speed);
96+ Serial.print (" clockwise, speed: " );
97+ Serial.print (speed);
9698 // step one revolution in one direction:
9799 myStepper.step (stepsPerRevolution);
98100 if (buttonPress.PRESSED )
@@ -109,7 +111,8 @@ void loop()
109111 // read speed from 12-bit ADC input (map 1-100; stepper doesn't like speed=0)
110112 speed = (long )(map (analogRead (pot), 0 , 4095 , 1 , 100 ));
111113 myStepper.setSpeed (speed);
112- Serial.printf (" counterclockwise, speed: %d " , speed);
114+ Serial.print (" clockwise, speed: " );
115+ Serial.print (speed);
113116 // step one revolution in the other direction:
114117 myStepper.step (-stepsPerRevolution);
115118 if (buttonPress.PRESSED )
0 commit comments