24-11-2017, 23:37
(Ten post był ostatnio modyfikowany: 07-12-2017, 11:41 przez CEO.
Powód edycji: Używamy znaczników [code]!
)
Dzięki za link krn78
Posiedziałem i w sumie udało mi się zrobić to co chcę
Posiedziałem i w sumie udało mi się zrobić to co chcę
Kod:
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int stepCount = 0; // number of steps the motor has taken
void setup() {
pinMode(7, OUTPUT); //elektrozwor
pinMode(6, OUTPUT); //elektrozawór
pinMode(5, INPUT_PULLUP); //czujnik zblizeniowy
digitalWrite(7, LOW); //Wyłączenie diody
digitalWrite(6, LOW);
digitalWrite(5, LOW);
}
void loop()
{
if (digitalRead(5) == LOW) { //Jeśli przycisk wciśnięty
digitalWrite(6, HIGH); //Włącz diodę
delay(1000); //Czekamy 10 sekund
digitalWrite(6, LOW); //Wyłączamy diodę
delay(1000);
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
delay(1000);
} else {
// read the sensor value:
int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}
}