This is what i have.. im working off code someone else wrote to control a sony video camera via LANC which is the protocol that speaks to the camera.. The interfacing with the camera is working ok so i wont post all the function calls at the bottom of the code cause it will be a lot.. im just trying to get buttons and switches to behave certain ways before calling the function to send the code.. theres a few variables that get set at the start which might not look active in what i have posted but during all my attempts to get it working i have evolved through different ideas and some thing are left over.. Also some of the functions use them as well..
The switchstate section is the main part im trying to get working.. The other millis() stuff is working well..
Also im just starting out so it might be really badly written at the moment.. Once i had it going i was planning to clean it up and maybe optimise things into more cohesive methods, at the moment im just trying to find my way..
#define lancPin 2
#define aPin 0
#define bitMicroSeconds 104
#define button 3
#define buttonTwo 4
#define mainswitch 7
byte ledPinState = 1;
long previousMillis = 601;
long previousMillistwo = 601;
unsigned long currentMillis;
unsigned long currentMillistwo;
int switchstate;
int oldswitchstate = 0;
void setup() {
// define pin modes for tx, rx, led pins:
pinMode(lancPin, INPUT);
pinMode(aPin,INPUT);
pinMode(button,INPUT);
pinMode(buttonTwo,INPUT);
Serial.begin(300);
}
int commandCode = 0;
void loop() {
currentMillis = millis();
currentMillistwo = millis();
if (digitalRead(button) == HIGH) {SendCode(40,0x1a);
previousMillis = currentMillis;
}
if ((digitalRead(button) == LOW) && (currentMillis - previousMillis) < 200) {SendCode(40,0x18);}
if ((digitalRead(button) == LOW) && (currentMillis - previousMillis) > 200 && (currentMillis - previousMillis) < 400) {SendCode(40,0x16);}
//if ((digitalRead(button) == LOW) && (currentMillis - previousMillis) > 400 && (currentMillis - previousMillis) < 500) {SendCode(40,0x14);}
//if ((digitalRead(button) == LOW) && (currentMillis - previousMillis) > 500 && (currentMillis - previousMillis) < 600) {SendCode(40,0x12);}
if (digitalRead(buttonTwo) == HIGH) {SendCode(40,0x0a);
previousMillistwo = currentMillistwo;
}
if ((digitalRead(buttonTwo) == LOW) && (currentMillistwo - previousMillistwo) < 200) {SendCode(40,0x08);}
if ((digitalRead(buttonTwo) == LOW) && (currentMillistwo - previousMillistwo) > 200 && (currentMillistwo - previousMillistwo) < 400) {SendCode(40,0x06);}
//if ((digitalRead(buttonTwo) == LOW) && (currentMillistwo - previousMillistwo) > 400 && (currentMillistwo - previousMillistwo) < 500) {SendCode(40,0x04);}
//if ((digitalRead(buttonTwo) == LOW) && (currentMillistwo - previousMillistwo) > 500 && (currentMillistwo - previousMillistwo) < 600) {SendCode(40,0x02);}
switchstate = digitalRead(mainswitch);
if ((switchstate == HIGH) && (oldswitchstate == LOW)) {SendCode(24,0x33);
//delay (100);
oldswitchstate = HIGH;
}
if ((switchstate == LOW) && (oldswitchstate == HIGH)) {SendCode(24,0x33);
//delay (100);
oldswitchstate = LOW;
}
So with the switchstate stuff im trying to get a normal switch (when switched on) to send a code (start recording) to the camera as if it was pressed once on a button and then when it gets switched off, send the code again (to stop the camera recording)... I want to use a switch instead of a button so it doesnt get knocked on the control panel i plan to build... if i could turn the switch on once and start recording then when i want to stop i just flick it back, thats what im hoping..
problem i have at the moment is when i switch it on, i think it keeps sending the code to the camera over and over, it doesnt seem to want to send only one short instance and thats it.. At least this is what i think is happening due to a few other experiments..