Welcome to the N1IR Electronics Website. Totally off the cuff, one take, unrehearsed video projects for anyone interested in amateur radio, electronic design, makers, hardware hackers and science.


Get off you duff and build something!
Training the hand and mind since 1982.

Tuesday, June 25, 2013

Simple DIce Project


Here is a very easy electronic dice project, we have done this before with discreet 74xx logic with a LM555, counter, adder and BCD to seven segment decoder, but this is far easier using the venerable ATTINY85V.

I programmed the ATTINY85V unconventionally using the Arduino 1.0 software, you can find instructions on how to do this at High-Low Tech Site. I did run into problems using the Arduino Uno as the programmer so I used my USBtinyISP from adafruit, I also made a zif adaptor socket some time ago (not pictured) to work with the USBtinyISP.

531946274_dcd8763cda_o.jpg

Sorry for the labelling of the schematic and PCB I only had an hour to design, test and build it on the breadboard and mill the PCB, so I did this one very hastily, next version should be cleaner. But that is pretty amazing from nothing to working prototype on a PCB and breadboard in under an hour, 10 years ago using standard etching I would've taken 4 to 6 hours to do the same.




 


here is the code
***********************************************************************************
int pinLeds1 = 3;
int pinLeds2 = 2;
int pinLeds3 = 1;
int pinLed4 = 0;
int buttonPin = 4;
int buttonState;
long ran;
int time = 2000;

void setup ()
{
  randomSeed(analogRead(0));
  pinMode (pinLeds1, OUTPUT);
  pinMode (pinLeds2, OUTPUT);
  pinMode (pinLeds3, OUTPUT);
  pinMode (pinLed4, OUTPUT);
  pinMode (buttonPin, INPUT);
  }

void loop()
{
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH){
    ran = random(1, 7);
    if (ran == 1){
      digitalWrite (pinLed4, HIGH);
      delay (time);
    }
    if (ran == 2){
      digitalWrite (pinLeds1, HIGH);
      delay (time);
    }
    if (ran == 3){
      digitalWrite (pinLeds3, HIGH);
      digitalWrite (pinLed4, HIGH);
      delay (time);
    }
    if (ran == 4){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds3, HIGH);
      delay (time);
    }
    if (ran == 5){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds3, HIGH);
      digitalWrite (pinLed4, HIGH);
      delay (time);
   }
   if (ran == 6){
      digitalWrite (pinLeds1, HIGH);
      digitalWrite (pinLeds2, HIGH);
      digitalWrite (pinLeds3, HIGH);
      delay (time);
   }
  }
  digitalWrite (pinLeds1, LOW);
  digitalWrite (pinLeds2, LOW);
  digitalWrite (pinLeds3, LOW);
  digitalWrite (pinLed4, LOW);
}
***********************************************************************************