Easy switching on/off , but hard for newbie!
hi
hope can help?
i have 1x relay use switch randomly lighting between 2 incandescent lights, when 1 lit other out, , vice versa. have gotten lights work through relay cant understand random , randomseed states...
i want set min , max seconds time delay lights lit , relay switches between 2 lights.
hope make sense?
and hope me sketch works cause dont understand , brain muchy now
regards
per
hope can help?
i have 1x relay use switch randomly lighting between 2 incandescent lights, when 1 lit other out, , vice versa. have gotten lights work through relay cant understand random , randomseed states...
i want set min , max seconds time delay lights lit , relay switches between 2 lights.
hope make sense?
and hope me sketch works cause dont understand , brain muchy now
regards
per
you mus use, said, random() function. function, don't gives random number (almost random), , start working need randomseed(), start process of generating "random" numbers. make the random() function generate little more random numbers need seed random number. can use analog input when it's not connected (and picks noise, random).
the technical explanation without many technical details this. code, can start example of page:
http://arduino.cc/en/reference/random
to this, can use map() function, or can use random(min, max)
so, can this:
note: didn't try it.
the technical explanation without many technical details this. code, can start example of page:
http://arduino.cc/en/reference/random
hi
(...)i want set min , max seconds time delay lights lit , relay switches between 2 lights.
hope make sense?
(...)
to this, can use map() function, or can use random(min, max)
so, can this:
code: [select]
const int relaypin = 13;
long randnumber;
int min = 1000;
int max = 1500;
boolean state=false;
void setup(){
serial.begin(9600);
pinmode(relaypin, output);
randomseed(analogread(0));
}
void loop() {
randnumber = random(min, max);
serial.println(randnumber);
if (state == false) {
state = true;
digitalwrite(relaypin, high);
}
else {
state = false;
digitalwrite(relaypin, low);
}
delay (randnumber);
}
note: didn't try it.
Arduino Forum > Using Arduino > Programming Questions > Easy switching on/off , but hard for newbie!
arduino
Comments
Post a Comment