int Index; const int analogInPin = A0; // Analog input pin that the potentiometer is attached to int sensorValue = 0; // value read from the pot unsigned long outputValue = 0; // value output to the PWM (analog out) unsigned long nextHalfStepTime = 0; bool stepPinState = LOW; unsigned char buffer[1000]; void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); pinMode(6, OUTPUT); //enable pinMode(5, OUTPUT); //step pinMode(4, OUTPUT); //direction digitalWrite(6, LOW); //enable on digitalWrite(5, stepPinState); } void loop() { // read the analog in value: sensorValue = analogRead(analogInPin); // map it to the range of the analog out: outputValue = map(sensorValue, 0, 1023, 5000, 0); // change the analog out value: //analogWrite(analogOutPin, outputValue); if (outputValue != 5000){ digitalWrite(4, LOW);} else (outputValue = 5000);{ digitalWrite(6,HIGH); if(micros() > nextHalfStepTime) { stepPinState = !stepPinState; digitalWrite(5, stepPinState); nextHalfStepTime += outputValue; } } // print the results to the serial monitor: //Serial.print("sensor = "); //Serial.print(sensorValue); //Serial.print("\t output = "); //Serial.println(outputValue); /*if (outputValue != 5000){ digitalWrite(4, LOW); for (Index = 0; Index < 1600; Index++) { digitalWrite(5, HIGH); delayMicroseconds(outputValue); digitalWrite(5, LOW); delayMicroseconds(outputValue); } delay(2);*/ unsigned numBytes = Serial.available(); if (numBytes) { Serial.readBytes(buffer, numBytes); Serial.print("sensor = "); Serial.print(sensorValue); Serial.print("\t output = "); Serial.println(outputValue); } }