/*
Original question :
I am trying to set up a solenoid so that it moves when a toggle switch is moved from
one position to another, but the output from the Arduino needs to be a pulse about 20ms
long so that the solenoid doesn't remain powered. I am using the Arduino to drive a
couple of MOSFETs that supplies the power to the solenoid poles
*/
#include "onePulsePin.h" // The non-blocking one shot pulse out class.
#include <mechButton.h> // Button debouncing library.
#define PULSE_PIN_R 2 // The right pulse will be run on pin #2
#define PULSE_PIN_L 3 // The left pulse will be run on pin #3
#define SWITCH_PIN_R 4 // The button for the thing will be on pin #3
#define SWITCH_PIN_L 5 // The button for the thing will be on pin #3
#define PULSE_MS 100
onePulsePin pulseR(PULSE_PIN_R); // Create the right pulse object. (The pin that pulses)
onePulsePin pulseL(PULSE_PIN_L); // Create the left pulse object. (The pin that pulses)
mechButton switchR(SWITCH_PIN_R); // Create the right switch object.
mechButton switchL(SWITCH_PIN_L); // Create the left switch object.
void setup() {
switchR.setCallback(doSlideR); // Tell switch to to call this function when changed.
switchL.setCallback(doSlideL); // Tell switch to to call this function when changed.
digitalWrite(PULSE_PIN_R,LOW);
digitalWrite(PULSE_PIN_L,LOW);
}
// When there's a change on the right switch pin, this function will be called.
void doSlideR(void) {
if (!switchR.trueFalse()) { // If the switch pin has been grounded..
pulseR.pulse(PULSE_MS,HIGH); // Do a HIGH pulse to the thing for this amount of ms.
}
}
// When there's a change on the left switch pin, this function will be called.
void doSlideL(void) {
if (!switchL.trueFalse()) { // If the switch pin has been grounded..
pulseL.pulse(PULSE_MS,HIGH); // Do a HIGH pulse to the thing for this amount of ms.
}
}
void loop() {
idle(); // idle() lets all the magic happen behind the scenes.
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
led1:A
led1:C
led2:A
led2:C
sw1:1
sw1:2
sw1:3