Samotné otáčení je ok, nebo například ovládání led diody, ale ovládání nevím jak propojit. Pomůže někdo prosím?
Kód: Vybrat vše
#define dirPin 2
#define stepPin 3
#define stepsPerRevolution 200
int state = 0;
void setup() {
// Declare pins as output:
Serial.begin(9600); // Default communication rate of the Bluetooth module
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(dirPin, LOW);
for (int i = 0; i < 1 * stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(3000);
// Set the spinning direction counterclockwise:
digitalWrite(dirPin, HIGH);
for (int i = 0; i < 1 * stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(500);
}
void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}
if (state == '1') {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
state = 0;
}
}
Gilhad