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

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


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

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support