jdfgg — Arduino Uno simulation

gfdagd

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by kotovych-mykhaylo23.

Components

Sketch code

#include <Stepper.h>
#define BT1 2
#define BT2 3 
#define BT3 4

bool BT1N;
bool BT1V = 0;
bool i = false;
int PAS = 7;
int PASP = 0;
bool BT2V;
bool BT2N = 0;
bool BT3N = 0;
const int SPR = 800;
unsigned long t0;
bool ct = false;
Stepper Step(SPR, 8, 9);

void setup() {
  pinMode(BT1, INPUT);
  pinMode(BT2, INPUT);
  pinMode(BT3, INPUT);
  Step.setSpeed(1);
  delay(100);
}

void loop() {
  BT1N = digitalRead(BT1);
  if (BT1N == HIGH && BT1V == LOW) {
    i = true;
    if (PAS == 0) PAS = 7;
  }
  BT1V = BT1N;
  
  if (i == true) {
    Step.setSpeed(1);
    Step.step(PAS);
    PASP = PASP + PAS;
    if (PASP >= SPR) {
      PAS = 0;
      i = false;
    }
  }

  BT2N = digitalRead(BT2);
  if (BT2N == HIGH && BT2V == LOW) {
    i = 0;
    t0 = millis();
    PAS = 7;
    ct = true;
  } 
  
  if (BT2N == HIGH && BT2V == HIGH && ct == true) {
    if (millis() - t0 >= 3000) {
      if (PASP == 0) { 
        do{}
        
        Step.setSpeed(60);
        Step.step(200);
      } else {
        Step.setSpeed(60);
        Step.step(-PASP);
      }
      PASP = 0;
      ct = false;
    }
  }
  
  if (BT2N == LOW) {
    ct = false;
  }
  
  BT2V = BT2N;
}