I am using Arduino Uno R3 and Motor Shield to test solenoids. 2-state solenoids state is chanced when voltage is added. When you chance polarity and add voltage state chances again. 100ms pulse is used to control solenoid.
Everything is working now but I want to use push button to chance state. In addition I would like to use same button to run endurance test which chances state eg. 100 times. I was thinking that state would chance with quick push of the button. Endurance test could be selected with longer push(2 seconds or so). What do you think? I am not so familiar with programming and loops.
Tester code with endurance test(never ending loop) below. Feel free to help
Solenoid tester 2023
/*************************************************************
Original version:
Motor Shield 1-Channel DC Motor Demo
by Randy Sarafan
*************************************************************/
void setup() {
//Setup Channel A & B
pinMode(12, OUTPUT); //Initiates Channel A pin
pinMode(13, OUTPUT); //Initiates Channel B pin
}
void loop(){
//positive pulse
digitalWrite(12, HIGH ); //Positive polarity @ Channel A
digitalWrite(13, HIGH ); //Positive polairty @ Channel B
analogWrite(3, 255); //Channel A voltage 12V
analogWrite(11, 255); //Channel B voltage 12V
delay(100); //Pulse length 100ms
analogWrite(3, 0); //Channel A voltage 0V
analogWrite(11, 0); //Channel A voltage 0V
delay(1000);
//negative pulse
digitalWrite(12, LOW); //Negative polarity @ Channel A
digitalWrite(13, LOW); //Negative polarity @ Channel B
analogWrite(3, 255); //Channel A voltage 12V
analogWrite(11, 255); //Channel B voltage 12V
delay(100); //Pulse length 100ms
analogWrite(3, 0); //Channel A voltage 0V
analogWrite(11, 0); //Channel B voltage 0V
delay(1000);
}