Need help in choosing the right code for my project
hello everyone, i'm barak , i'm pretty new in programming , arduino.
i'm asking code, i'm having trouble choosing right timing code , coding it.
this code make:
what need in cod, when press on button, want cw relay go operation 20 seconds, shut automatically @ end of 20 seconds, , on relaypin relay , keep on.
when leaving button - off mode, relay relaypin going off , , turn on ccw relay 20 seconds, after ccw relay go off.
thanks helpers...
i'm asking code, i'm having trouble choosing right timing code , coding it.
this code make:
code: [select]
const int buttonpin = 2; // number of pushbutton pin
const int relaypin = 8; // number of relay pin
const int cw = 9; // number of cw pin
const int ccw = 10; // number of ccw pin
// variables change:
int buttonstate = 0; // variable reading pushbutton status
void setup() {
pinmode(cw, output);// initialize cw pin output:
pinmode(ccw, output);// initialize ccw pin output:
pinmode(relaypin, output); // initialize relay pin output:
pinmode(buttonpin, input); // initialize pushbutton pin input:
}
void loop() {
// read state of pushbutton value:
buttonstate = digitalread(buttonpin);
// check if pushbutton pressed. if is, buttonstate high:
if (buttonstate == high) {
digitalwrite(cw,high); //motor runs clockwise//
digitalwrite(ccw, low); //motor stops//
digitalwrite(relaypin, low);//relay on//
} else {
digitalwrite(relaypin, high);//relay off//
digitalwrite(ccw, high);//motor runs counter-clockwise//
digitalwrite(ccw, low); //motor stops//
}
}
what need in cod, when press on button, want cw relay go operation 20 seconds, shut automatically @ end of 20 seconds, , on relaypin relay , keep on.
when leaving button - off mode, relay relaypin going off , , turn on ccw relay 20 seconds, after ccw relay go off.
thanks helpers...
what need in cod, when press on button, want cw relay go operation 20 seconds, shut automatically @ end of 20 seconds, , on relaypin relay , keep on.can clarify mean 'leaving button'? mean exact point when user stops pressing it? or time not pressed?
when leaving button - off mode, relay relaypin going off , , turn on ccw relay 20 seconds, after ccw relay go off.
what happens if user presses button during cw on time or ccw on time?
or mean?
when user presses button
cw goes on
wait 20 seconds
cw goes off , relay goes on
ccw goes on
wait 20 seconds
ccw goes off , relay goes off
nothing happen until user presses button again
ultimately need able describe states of system in terms of cw, ccw, relay , have clear rules on when system should change 1 state (e.g. after time, when input changes etc). lot easier help.
you have tried @ moment not clear (at least not me).
in meantime google 'state machine' , read this forum post.
Arduino Forum > Using Arduino > Programming Questions > Need help in choosing the right code for my project
arduino
Comments
Post a Comment