Help with Code
i had friend write code me control of functions in car, friend writes code living , wrote code free dont want keep bugin him modifications thought ill bug guys. hope 1 can me add small new function @ end of code. explained in code. hope im not braking forum rules , hope can help.
code: [select]
#define reverse_pin 5
#define switch_pin 6
#define lights_on 2
#define close_pin 3
#define open_pin 4
#define tiltup_pin 9
#define tiltdn_pin 10
#define m1_pin 11
#define m2_pin 12
#define lid_switch 7
#define lid_open 8
#define fog_lights 13
#define tilttmr 3000
#define closetmr 4000
boolean tiltuplock=false,closemrrlk=true;
void setup (){
pinmode(reverse_pin,input);
pinmode(switch_pin,input);
pinmode(close_pin,input);
pinmode(open_pin,input);
pinmode(tiltup_pin,output);
pinmode(tiltdn_pin,output);
pinmode(m1_pin,output);
pinmode(m2_pin,output);
pinmode(lid_switch,output);
pinmode(lights_on,input);
digitalwrite(tiltup_pin,low);
digitalwrite(tiltdn_pin,low);
digitalwrite(m1_pin,low);
digitalwrite(m2_pin,low);
digitalwrite(lid_open,low);
digitalwrite(fog_lights,low);
}
void loop(){
if(digitalread(switch_pin)){
if(digitalread(reverse_pin)&&tiltuplock){//tilt down
delay(2000);
if(digitalread(reverse_pin)){
tiltuplock=false;
digitalwrite(tiltdn_pin,high);
delay(tilttmr);
digitalwrite(tiltdn_pin,low);
}
}
if(!digitalread(reverse_pin)&&!tiltuplock){//tilt up
tiltuplock=true;
digitalwrite(tiltup_pin,high);
delay(tilttmr);
digitalwrite(tiltup_pin,low);
}
}
else{
if(digitalread(open_pin)&&!digitalread(close_pin)&&!closemrrlk){//close mirror
closemrrlk=true;
digitalwrite(m1_pin,high);
delay(closetmr);
digitalwrite(m1_pin,low);
}
if(!digitalread(open_pin)&&digitalread(close_pin)&&closemrrlk){//open mirror
closemrrlk=false;
digitalwrite(m2_pin,high);
delay(closetmr);
digitalwrite(m2_pin,low);
}
}
// added open fuel cap lid. if switch pressed activate relay - please check if correct
// read state of lid_switch value:
// check if lid_switch pressed.
// if is, buttonstate high:
if (lid_switch == high) {
// open fuel lid:
digitalwrite(lid_open, high);
} else {
// close fuel lid:
digitalwrite(lid_open, low);
}
}
// want add 1 more statement - if switch pin 6 high , lights_on pin 2 high fog_lights pin 13 should high, esle turn of fog_lights
why not try ?
use other tests , actions examples
use other tests , actions examples
Arduino Forum > Using Arduino > Programming Questions > Help with Code
arduino
Comments
Post a Comment