Can anyone pls help in using stepper.h and its included pls help me.
Best you read the intro on how to post here.
Bare minimum would be a copy of your code ( in code brackets as required) and a circuit diagram of what you have in front of you. (Not Fritzing)
Anything less becomes" I have a car and it's broken...what's wrong with it?"
oh. ok ty blue jets
Code:
#include <Servo.h>
#include <Stepper.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int Forward;
const int trigPin = 5;
const int echoPin = 6;
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = A0; // analog pin connected to X output
const int Y_pin = A1; // analog pin connected to Y output
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
const int rolePerMinute = 15; // Adjustable range of 28BYJ-48 stepper is 0~17 rpm
float duration, distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(11, OUTPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(SW_pin, INPUT);
digitalWrite(SW_pin, HIGH);
Stepper.setSpeed(rolePerMinute)
// initialize the serial port:
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Servo
//val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
//val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
val = (val + 2);
myservo.write(val); // sets the servo position according to the scaled value
if (val > 175) {
val = -40;
}
//Path Finding Here
if (distance > 23) {
Forward = 'true';
}
else if (distance < 23) {
Forward = 'false';
}
else {
Serial.print('ERROR');
}
// JoyStick
int X = A1;
int Y = A2;
duration = pulseIn(echoPin, HIGH);
distance = (duration*.0343)/2;
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print(" ");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print(" ");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("Distance: ");
Serial.println(distance);
Serial.print("Motor:");
Serial.print(val);
Serial.print(" ");
//Path Finding
if (Forward = 'true') {
}
else if (Forward = 'false') {
}
delay(20);
}
Try to egnore the other stuff ![]()
Should be global ‘scope’, not local within setup()
ok ill try that ty
it works!!! tysm!!!!!!!
You will also have to fix some of those warnings:
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino:50:15: warning: character constant too long for its type
Forward = 'true';
^~~~~~
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino:53:15: warning: character constant too long for its type
Forward = 'false';
^~~~~~~
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino:56:18: warning: character constant too long for its type
Serial.print('ERROR');
^~~~~~~
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino:78:17: warning: character constant too long for its type
if (Forward = 'true') {
^~~~~~
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino:80:22: warning: character constant too long for its type
else if (Forward = 'false') {
^~~~~~~
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino: In function 'void setup()':
sketch_jun09a:28:10: error: expected unqualified-id before '.' token
Stepper.setSpeed(rolePerMinute)
^
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino: In function 'void loop()':
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino:78:15: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if (Forward = 'true') {
~~~~~~~~^~~~~~~~
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino:80:20: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
else if (Forward = 'false') {
~~~~~~~~^~~~~~~~~
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino:59:7: warning: unused variable 'X' [-Wunused-variable]
int X = A1;
^
/tmp/arduino_modified_sketch_739258/sketch_jun09a.ino:60:7: warning: unused variable 'Y' [-Wunused-variable]
int Y = A2;
^
Forward = 'true';
Forward is an int, you can't assign some form of text to it, only one character. Make forward a bool variable and assign true or false to it.
if (Forward = 'true') {
Single = for assigment, double == for compare.
I suggest that you set Compiler warnings to all in File/Preferences.
ok ty
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.