// program to test whether a servo will stay
// in position after signal is removed.
#include <EEPROM.h>
// preset values
const byte posn1Val = 165;
const byte posn2Val = 130;
// Input pins
const byte posn1Sw = 4;
const byte posn2Sw = 5;
const byte inputModeSw = 6;
const byte outputModeSw = 7;
// Output pins
const byte positionOut = 9;
byte outputValue;
void setup() {
Serial.begin(115200);
pinMode(posn1Sw, INPUT_PULLUP);
pinMode(posn2Sw, INPUT_PULLUP);
pinMode(inputModeSw, INPUT_PULLUP);
pinMode(outputModeSw, INPUT_PULLUP);
}
void loop() {
if(digitalRead(posn1Sw)==LOW) outputValue=posn1Val;
if(digitalRead(posn2Sw)==LOW) outputValue=posn2Val;
analogWrite(positionOut,outputValue);
// set to input to test holding
if(digitalRead(inputModeSw)==LOW) pinMode(positionOut,INPUT);
Serial.println(outputValue);
}