// Stepper motor on Wokwi!
#include <Stepper.h>
const int stepsPerRevolution = 400; // change this to fit the number of steps per revolution
const int R = 7;
const int G = 6;
const int B = 5;
const int button1 = 12;
const int button2 = 13;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// button stuff
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// reset led colors
RGB_color(255,255,0);
if (digitalRead(button1) == LOW) {
// click
RGB_color(255,0,255); //green
// step one revolution in one direction:
Serial.println("clockwise btn1");
myStepper.step(stepsPerRevolution);
//delay(500);
}
if (digitalRead(button1) == HIGH) {
RGB_color(0,255,255);
Serial.println("nada button 1");
}
if (digitalRead(button2) == LOW) {
// click
RGB_color(0,0,255); //yellow
// step one revolution in the other direction:
Serial.println("counterclockwise btn2");
myStepper.step(-stepsPerRevolution);
//delay(500);
}
if (digitalRead(button2) == HIGH) {
RGB_color(0,255,255);
Serial.println("nada button 2");
}
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value)
{
analogWrite(R, red_light_value);
analogWrite(G, green_light_value);
analogWrite(B, blue_light_value);
}