Hi there, First time posting a project up here.
I have designed and coded a circuit for the ATTiny85 that Randomly blinks at random durations 1 of 4 LEDs.
I am only using 2 of the 6 pins available on the chip by using the Tri state function of the GPIO pins.
(in plain English, I made the two pins do 3 different things, Sink, source, and Open (or HI-Z))
I programmed everything with the MIT method using an Uno as an ICSP.
The relevant part of this project is the code. I'm not sure if anyone has posted anything similar but I pretty much did this without much reference to anything else.
here is the code.
/*
Code by Nick Tracy 2013
May contain code parts from other programs, all credit goes to those who helped.
Designed around the ATTiny85 @ 8 Mhz with internal oscillator, accuracy is not important here and is actually beneficial.
This code uses a random number generator to simulate a twinkling effect on 4 different outputs.
Used in a decoration for the holidays, can be used for just about anything really.
it uses 4 LEDs connected to 2 pins (3 and 4 for ATTiny85) that are Tri-stated to provide a HIGH, LOW, and High Impedance output.
the LEDs are connected in a sink/source set up on each pin. when the pin mode is changed to the third state the LEDs on that pin are off.
*/
//Use Define so that not a lot of memory is wasted.
#define LED1 3
#define LED2 4
//long for random number variables
long rand1;
long rand2;
long rand3;
void setup() {
pinMode(LED1, INPUT_PULLUP);
pinMode(LED2, INPUT_PULLUP);
//Generate Random numbers seed
randomSeed(12345612);
}
void loop() {
rand1 = random(1,5); //Used for selecting which LED to fire.
rand2 = random(5,20); //Used to determine delay for On.
rand3 = random(50,300); //Used to determine delay for Off.
//Switch case for selecting the appropriate LED
//Fires one Random LED at a time each loop at a random duration On and Off.
switch (rand1){
case 1:
pinMode(LED1, OUTPUT); //set pin mode to output
pinMode(LED2, INPUT_PULLUP); //makes sure other output is off
digitalWrite(LED1, HIGH); //turn on led number 1 of 4
delay(rand2); //delay for On duration
pinMode(LED1, INPUT_PULLUP); //turn off the output
delay(rand3); //delay before next cycle
break;
case 2:
pinMode(LED1, OUTPUT); //set pin mode to output
pinMode(LED2, INPUT_PULLUP); //makes sure other output is off
digitalWrite(LED1, LOW); //turn on led number 2 of 4
delay(rand2); //delay for On duration
pinMode(LED1, INPUT_PULLUP); //turn off the output
delay(rand3); //delay before next cycle
break;
case 3:
pinMode(LED2, OUTPUT); //set pin mode to output
pinMode(LED1, INPUT_PULLUP); //makes sure other output is off
digitalWrite(LED2, HIGH); //turn on led number 3 of 4
delay(rand2); //delay for On duration
pinMode(LED2, INPUT_PULLUP); //turn off the output
delay(rand3); //delay before next cycle
break;
case 4:
pinMode(LED2, OUTPUT); //set pin mode to output
pinMode(LED1, INPUT_PULLUP); //makes sure other output is off
digitalWrite(LED2, LOW); //turn on led number 4 of 4
delay(rand2); //delay for On duration
pinMode(LED2, INPUT_PULLUP); //turn off the output
delay(rand3); //delay before next cycle
break;
default:
//If no LED is selected, turn off all LEDs for a random amount of time.
pinMode(LED1, INPUT_PULLUP);
pinMode(LED2, INPUT_PULLUP);
delay(rand2);
}
}
EDIT: The LEDs I used were White with a 3.2v drop and 20ma draw. but with different resistor values you can use any LED so long as you choose the correct current limiting resistor for your LED.
My only issue here is that two of the LEDs are dimly lit in the HI-Z state due to the internal pull up resistors. there is just enough current to light the LEDs I'm using. if anyone has a recommendation for that let me know.