Random blink

I just managed to get some LEDS blinking in my balcony. So I have no problems. But if you have ideas or comments I am happy to hear about them.
This is my program.

/*Begining of Auto generated code by Atmel studio */
#include <Arduino.h>
int Pin0 = A0;
int Pin1 = A1;
int Pin2 = A2;
int Pin3 = A3;
int Pin4 = A4;
int Pin5 = A5;
int Pin6 = 4;  //PD4, pin 6
int Pin7 = 9;  //PB1, pin 15
long arpa;
//byte bitit;
void ledjut(long);
void viive(long );
void setup() {
  // put your setup code here, to run once:
pinMode(Pin0, OUTPUT); 
pinMode(Pin1, OUTPUT); 
pinMode(Pin2, OUTPUT); 
pinMode(Pin3, OUTPUT); 
pinMode(Pin4, OUTPUT); 
pinMode(Pin5, OUTPUT); 
pinMode(Pin6, OUTPUT); 
pinMode(Pin7, OUTPUT); 

digitalWrite(Pin2, HIGH);
digitalWrite(Pin3, HIGH);
digitalWrite(Pin4, HIGH);
digitalWrite(Pin5, HIGH);
digitalWrite(Pin6, HIGH);
digitalWrite(Pin7, HIGH);

randomSeed(analogRead(0));

}

void loop() {
  // put your main code here, to run repeatedly:
arpa=random(255);
ledjut(arpa);
arpa=random(20);
viive(arpa);

}

void ledjut(long luku)
{

if (bitRead(luku, 0)==1)
{
	digitalWrite(Pin0, HIGH);
}
else
{
digitalWrite(Pin0, LOW);	
}

if (bitRead(luku, 1)==1)
{
	digitalWrite(Pin1, HIGH);
}
else
{
	digitalWrite(Pin1, LOW);
}

if (bitRead(luku, 2)==1)
{
	digitalWrite(Pin2, HIGH);
}
else
{
	digitalWrite(Pin2, LOW);
}

if (bitRead(luku, 3)==1)
{
	digitalWrite(Pin3, HIGH);
}
else
{
	digitalWrite(Pin3, LOW);
}

if (bitRead(luku, 4)==1)
{
	digitalWrite(Pin4, HIGH);
}
else
{
	digitalWrite(Pin4, LOW);
}

if (bitRead(luku, 5)==1)
{
	digitalWrite(Pin5, HIGH);
}
else
{
	digitalWrite(Pin5, LOW);
}

if (bitRead(luku, 6)==1)
{
	digitalWrite(Pin6, HIGH);
}
else
{
	digitalWrite(Pin6, LOW);
}

if (bitRead(luku, 7)==1)
{
	digitalWrite(Pin7, HIGH);
}
else
{
	digitalWrite(Pin7, LOW);
}

}

void viive(long viivel)
{
	while (viivel!=0)
	{
		delay(50);
		viivel--;
	} 
	
}

There are 8 LEDs connected to seemingly random 328 pins. I wanted to get random time and random pattern.

The board is my own and has no serial bus. I planned to to use the Atmel Studio but after some machine problems, I could not reinstall it. So, AVRDUDE was used and a hex file from new Arduino IDE. Also, Atmel studio messes the AVRISP II drivers, I had to get working drivers from an old IDE.

So, quite a bit of work for blinking some LEDs in my balcony, but atleast LED are very bright.

When you find yourself using a numeric suffix on variables (such as Pin0, Pin1, ..., Pin7), it is time to learn about arrays.

It wouldn't be a bad idea to learn about for-loops and functions as well.

The following should be functional identical.

const byte pin[] = { A0, A1, A2, A3, A4, A5, 4, 9};
void setup() {
  byte idx;
  for (idx=0; idx<sizeof(pin); idx++) {
    pinMode(pin[idx], OUTPUT);
  }
  for (idx=2; idx<sizeof(pin); idx++) {
    digitalWrite(pin[idx], HIGH);
  }
  randomSeed(analogRead(0));
}
void ledjut(byte luku) {
  for (byte idx=0; idx<8; idx++) {
    digitalWrite(pin[idx], bitRead(luku, idx));
  }
}
void loop() {
  ledjut(random(256));
  delay(random(1000));
}

Not bad. I think I even understand it

This code has been first in Arduino 1.78 then in Atmel Studio7 and now in Arduino 1.68. Functions suffer, especially their definitions/. And then there is me ofcourse.

Wrote this little sketch to randomly blink 3 LEDs, shouldn't be too hard to expand to 8. Give it a try.

const byte red = 5, grn = 6, yel = 7; // LED pins
const byte dur = 30; // duration of blink
const int mn = 500, mx = 2000; // interval between blinks
unsigned long strt1, strt2, strt3;
unsigned long ival1, ival2, ival3; // interval between blinks
byte cnt;

void setup() {
  Serial.begin(9600);
  pinMode(red,OUTPUT);
  pinMode(grn,OUTPUT);
  pinMode(yel,OUTPUT);
  strt1 = strt2 = strt3 = millis();
}

void loop() {
  if(cnt > 25){
    randomSeed(analogRead(5)); // new seed after 25 red blinks
    cnt = 0;
  }  
  if(millis() - strt1 > ival1) digitalWrite(red,HIGH);
  if(millis() - strt1 > ival1 + dur){
    digitalWrite(red,LOW);
    ival1 = random(mn,mx);
    strt1 = millis(); cnt++;
  }
  if(millis() - strt2 > ival2) digitalWrite(grn,HIGH);
  if(millis() - strt2 > ival2 + dur){
    digitalWrite(grn,LOW);
    ival2 = random(mn,mx);
    strt2 = millis();
  }
  if(millis() - strt3 > ival3) digitalWrite(yel,HIGH);
  if(millis() - strt3 > ival3 + dur){
    digitalWrite(yel,LOW);
    ival3 = random(mn,mx);
    strt3 = millis();
  }

}

Thank you.

One reason to write here was to get ideas about blinking. I have LEDs blinking still, but that's it. Nothing new or interesting. Getting new SW is fine, I may even learn new things, but what about end result. Has any one got an idea how to make the LEDs look different. Like not full random blink or some rhytm into that blink.

Have them fade up to full brightness

I got a flu and got other "things" in my head than programming.

Fading is a good idea, I thought about but I thought that my drivers are not fast enough. But fading does not need high speed, so I must try that.

I think I must try an other forum because I'm not asking for programming help than ideas