top of page

Class 4- final project

#include <Stepper.h> //הגדרת ספריה לשימוש במנוע

 

// הגדרת מספר הצעדים פר סיבוב

const int stepsPerRevolution = 2038;

 

// הגדרת כניסות גויסטיק

const int SV_pin = 2;

const int X_pin = 0;

const int Y_pin= 1 ;

const int joystick= A0 ;
 

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

 

void setup() {

pinMode(SV_pin, INPUT);

digitalWrite(SV_pin, HIGH);

Serial.begin(115200);

}

 

void loop() {

int joystickVal = analogRead(joystick);

Serial.print("switch: ");

Serial.print(digitalRead(SV_pin));

Serial.print("\n");

Serial.print("X-axis: ");

Serial.print(analogRead(X_pin));

Serial.print("\n");

Serial.print("Y-axis: ");

Serial.print(analogRead(Y_pin));

Serial.print("\n\n");

delay(500);

 

if ((joystickVal > 500) && (joystickVal < 523)) {

myStepper.setSpeed(0);

} else if (digitalRead(SV_pin) == LOW) {

myStepper.setSpeed(0);

} else {

int direction = (joystickVal > 523) ? 1 : -1;

int speed = map(joystickVal, 500, 1023, 5, 500);

myStepper.setSpeed(5);

myStepper.step(5);

}

}

גויסטיק ומנוע.png

Digital material culture

©2022 by Digital material culture. Proudly created with Wix.com

bottom of page