hi guys
back again, trying to add the jogging part for my motor to feed the label roll in m/c,but i just dont seem to win these { } brackets confuse me still, i quite dont get it. ill post the sketch the last part is my jogging section, i am stuck.
im not even sure if i have it at the right place. sorry still learning
//*
// Control of a 4 wire stepper motor with optical-sensor (TCST2103) high and low
// readings with led confirming sensor status, reading 28mm x 32mm label on a roll
// sensor reading 28mm edge of label. { Motor jogging function included.
// (Under Construction) }.
//*
#include <Stepper.h>
const int led = 13; // led indicator on pin 19
const int buttonPin = 3; // pushbutton on pin 5(motor inch)
const int sensor = 2; // sensor on pin 4
const int stepsPerRevolution = 200; // 1.8 degree step motor
Stepper myStepper(stepsPerRevolution, 9, 10, 11, 12);
int stepCount = 0; // number of steps the motor has taken
int buttonState = 0; // variable for reading the pushbutton status
int val = 0; // variable to store the sensor status (value)
void setup() {
pinMode(led, OUTPUT); // initialize LED as an output
pinMode(buttonPin, INPUT); // initialize pushbutton pin as an input:
pinMode(sensor, INPUT); // initialize sensor as an input
}
void loop() {
val = digitalRead(sensor); // read sensor value
if (val == LOW) { // check if the sensor is HIGH/LOW
digitalWrite(led, LOW); // turn led off
} else {
val = digitalRead(sensor); // read sensor value
if (val == HIGH)
digitalWrite(led, HIGH); // turn led on
int sensorReading = analogRead(A0); // pot to adjust motor speed
// map it to a range from 20 to 255:
int motorSpeed = map(sensorReading, 0, 1023, 20, 255);
if (motorSpeed > 0)
myStepper.setSpeed(motorSpeed); // set the motor speed:
// step 1/200 of a revolution:
myStepper.step(stepsPerRevolution / 200); // step 1/200 of a revolution:
// buttonState = digitalRead(buttonPin); // read the state of the pushbutton value:
// if (buttonState == HIGH); // the buttonState is HIGH:
// digitalWrite(led, HIGH); // turn led on
// myStepper.step(20); // stepper run 20rpm
// } else {
// if (buttonState == LOW); // the bottonState is LOW
// digitalWrite(led, LOW); // turn led off
// myStepper.step(0); // stepper stop
}
}
pls any help