Hello
I would like to know if there is a kind soul who can help me make a sketch.
It should work like this: a spring is wound up via a dc motor(motor1) connected to relay with an arm. The motor stops when the arm hits a sensor (INPUT1).
Then, if another sensor (INPUT2) is activated, it turns the relay to the motor (motor1) on again, but it should only run for a few seconds so the spring gets released and the hammer goes off.
After that, another motor (motor2) should move forward toward a switch and stop, then move back again to another switch and stop there (probably requires 2 relays).
And the condition for motor (motor1) to run again and reach (INPUT1) and stop, that is when sensor (INPUT2) is no longer activated.
I tried to mess around with one based on the button example, but I can't quite get there.
Using an ESP8266 D1 Mini
int buttonPin1 = 4; // the number of the pushbutton pin
int buttonPin2 = 12;
int ledPin = 5; // the number of the LED pin
int motorPin = 5;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonState1 = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
pinMode(motorPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin1);
buttonState1 = digitalRead(buttonPin2);
//# = digitalRead(buttonPin2);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} // else {
// turn LED off:
// digitalWrite(ledPin, LOW);
//}
if (buttonState == LOW) {
// turn LED on:
digitalWrite(ledPin, LOW);
}
// MUS i fælden
if (buttonState == LOW,buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, LOW);
} // else {
// turn LED off:
// digitalWrite(ledPin, LOW);
//}
//
if (buttonState == HIGH,buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} // else {
// turn LED off:
// digitalWrite(ledPin, LOW);
//}
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
//if (buttonState1 == HIGH) {
// turn LED on:
// digitalWrite(motorPin, HIGH);
// } else {
// turn LED off:
// digitalWrite(motorPin, LOW);
//}
}