hi all
i got a simple code and have modified it myself just want some one to check if the code is ok
i'm new at this and still learning the code
// Random flasher by mark oldroyd
// Simple random number flasher
// generation and integration into your circuit on the
// arduino.
//
// Circuit build : Simply connect 8 LED's to pins 3,4,5,6,7,8,9,10
// Be sure to connect a resistor to each LED. I used 330 ohms.
//
//
int ranNum;
int ranDel;
void setup() {
// Seed RNG from analog port.
randomSeed(analogRead(0));
// Setup 8 output ports for LED's
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
//Generate random number between 8 and 10
ranNum=random(3,11);
// Generate random delay time
ranDel=random(25,300);
//Turn on the LED
digitalWrite(ranNum, HIGH);
delay(ranDel);
//Turn off the LED
digitalWrite(ranNum, LOW);
}
void loop() {
//Generate random number between 8 and 10
ranNum=random(3,11);
// Generate random delay time
ranDel=random(25,300);
//Turn on the LED
digitalWrite(ranNum, HIGH);
delay(ranDel);
//Turn off the LED
digitalWrite(ranNum, LOW);
}
The LED is turned on, delays for a random amount of time, turned off and then within a split second, turned on again. Look at the Blink example and notice the second delay.
is this ok as i say i'm new to arduino i'm used to pic chips
//Generate random number between 8 and 10
ranNum=random(3,11);
// Generate random delay time
ranDel=random(100,400);
//Turn on the LED
digitalWrite(ranNum, HIGH);
delay(ranDel);
//Turn off the LED
digitalWrite(ranNum, LOW);
A problem you'll run into is that you're picking pin numbers between 3 and 10 inclusive, not all of which are capable of hardware PWM, which is useful for dimming.
I'd put the PWM pin numbers into an array, and use the random number to provide an index into that array.
Fantastic project, this is what I was looking for to make my drawbot work autonomously
I still have a question, is it possible to burn the 2 LEDs that I use simultaneously as random
So you could choose between 1led on, or 2nd led on or both on in random
Can you help me please
int ranNum;
int ranDel;
void setup() {
Serial.begin(9600);
Serial.println("Starting new Random Number Sequence");
randomSeed(analogRead(0)); // Seed RNG from analog port.
pinMode(2, OUTPUT); // Setup 2 output ports for LED's
pinMode(3, OUTPUT);
}
void loop() {
ranNum=random(2,4); // Generate random number between 2 and 3
ranDel=random(25,300); // Generate random delay time 25,300
digitalWrite(ranNum, HIGH); // Turn on the LED
delay(ranDel);
digitalWrite(ranNum, LOW); // Turn off the LED
delay(ranDel);
Serial.print("The Random Number is = ");
Serial.println(ranNum : ranDel) ;
//Serial.print("The Random Delay is = ");
//Serial.println(ranDel);
}