Monday, September 21, 2020

LED Sand Clock

A fun project to build an electronic sand clock with ATtiny85 from scratch.


There are 4 direction for the "sand" to fall

 


 


It consists of 3 modules:
Display, Control unit and Sensor.


There are 3 wires to control the display and 1 wire to get the direction from the sensor. Every part can be replaced.

Controls:
 



Schematics:



Display

 
You can see two 4011C (4x NAND Gate) on the top and CD4040BE (12-Stage Ripple-Carry Binary Counter/Divider) on the right side.

30 LEDs are divided in 3 pages. Pins 1-10 of the binary counter controls the group position. Combination of the pins 11 and 12 controls the page number. 00 - first page, 01 - second and 10 - third.


Sensor


Direction sensor uses 4 tilt sensors to find the top direction. Each tilt sensor sends another value to the analog pin.

Code:


Global variables:

int setPin = 0;
int resetPin = 1;
int lightOnPin = 2;
int buttonPin = 3; // pin for the change mode button
int sensorPin = A2; // pin for th edirection sensor

int sensorValue = 0;  // variable to store the value coming from the sensor
int dotSpeed = 8; // move dot every X loop
int loopCounter = 0; // count every game loop (max 1023 then reset)
int display_mode = 1; // 1-15 number of displayed dots or tests
int cur_number_of_dots = 1; 
const byte MAX_NUMBER_OF_DOTS = 30;
unsigned int dots[MAX_NUMBER_OF_DOTS] = { // positions of the dots
  1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30
}; 

/**
 *     1
 *   2   4
 *     3
 */
unsigned int top_direction;
char compas[5] = "*NESW";
 
const byte NUMBER_OF_POSITIONS = 30;
unsigned int screenMap[NUMBER_OF_POSITIONS] = {
  B00000001+2048,B00000001+1024,B00000010+1024,B00000100+2048,B00000100+1024,               //  1, 2, 3, 4, 5
    B00000001,B00000010+2048,B00000010,B00000100,                                           //   6, 7, 8, 9
            B00001000+2048,B00001000,B00001000+1024,                                        //    10,11,12
                  B00010000+2048,B00010000+1024,                                            //     13,14
                      B00010000,                                                            //       15
                      B00100000,                                                            //       16
                  B00100000+2048,B00100000+1024,                                            //     17,18
            B01000000+2048,B01000000,B01000000+1024,                                        //    19,20,21 
    B00000000+512,B00000000+256+2048,B00000000+256,B10000000,                               //   22,23,24,25
  B00000000+512+2048,B00000000+512+1024,B00000000+256+1024,B10000000+2048,B10000000+1024,   //  26,27,28,29,30
};
unsigned int position; 


How to print the dots:

void sandClockMode() {
  int groupA = 0;
  int groupB = 0;
  int groupC = 0;

  for (int i = 0; i < cur_number_of_dots; i++) {
    position = dots[i];
    if (!(loopCounter % dotSpeed)) {
        position = findNewPosWithGravity(position);
    }

    dots[i] = position;
    if (screenMap[position-1] > 2048) {
      groupA = groupA | screenMap[position-1];
    } else if (screenMap[position-1] > 1024) {
      groupB = groupB | screenMap[position-1];
    } else {
      groupC = groupC | screenMap[position-1];
    }
  }
  printDot(groupA);
  printDot(groupB);
  printDot(groupC);
}


Sensor code:

int readSensor() {
  sensorValue = analogRead(sensorPin);
  //  0 - undefined, 1 - N, 2 - E, 3 - S, 4 - W
  if (sensorValue == 0 ) {
    topDirection = 0;
  } else if (sensorValue > 900) {
    topDirection = 3;
  } else if (sensorValue > 400) {
    topDirection = 4; 
  } else if  (sensorValue > 200) {
    topDirection = 1; 
  } else {
    topDirection = 2; 
  }  
  return topDirection;
}


How to move dots:

/**
 * Find the new position with gravity sensor
 * @param int pos
 * @return int
 */
int findNewPosWithGravity(int pos) {
  dir = getDirection();

  if (pos == 1) {
    if (dir == 1) {
      pos = 6;
    } else if (dir == 2) {
      if (!isPositionFree(2)) {
        pos = 6;
      } else {
        pos = 2;
      }      
    }
  } else if (pos == 2) {
    if (dir == 1) {
      if (!isPositionFree(10)) {
        if (!isPositionFree(6)) {
          pos = 7;
        } else {
          pos = 6;
        }        
      } else {
        pos = 10;
      }
    }
... and so on...


How to check if position is free
/**
 * Find out it the given position is free
 * @param int pos
 * @return bool
 */
bool isPositionFree(int pos) {
  for (int i = 0; i < cur_number_of_dots; i++) {
    if (dots[i] == pos) {
      return false;
    }
  }
  return true;
}

Labels: , ,

Click here to see the whole post!

Monday, July 13, 2015

Sudoku calculator



Any sudoku fans out there? Did you have some sudokus, that you wasn't able to complete? Here is the solution - a program that solves the sudokus for you.  ;)

Actually that was a fun project. To calculate the puzzle, without using brute force. Et voilà! This calculator can find the solution of the simple sudoku, with some kind of heuristic or uses the brute force, for the complicated one.



You can try the demo here.

Or get it on the github. (Open Source. Do what you want with it.)


It is possible to add mode methods to solve the puzzles if you need them.

It is also possible to add more game fields, like samurai-sudoku or nanominosudoku. Or redesign the game field and add more colours. The data format is quite simple.



Labels: , , , ,

Click here to see the whole post!

Tuesday, April 01, 2014

Silent Hill 2 Game Boy OST



As you already know, the Silent Hill 2 for Game Boy was released in 2009 (see my post about it). The game has some kind of a cult status now and is one of the most wanted games of the SH series.








The soundtrack was released a couple of months later, but was instantly sold out. At first it was still possible to get the CD on the Amazon (it was quite expensive), but I wasn't lucky enough to get my copy.





But yesterday Ilthanar found this disc at the local discouter for 7.99!!! Amazing!




There are overall 5 Game-Boy-quality tracks on the disc:

01 - Theme Of Laura
02 - Promise (Reprise)
03 - True
04 - Theme Of Laura (Reprise)
05 - Promise

Listen all tracks on youtube.


Labels: , , ,

Click here to see the whole post!

Sunday, June 28, 2009

NecroQuest merchandising thread go!
How 2d characters go 3d. (^_^)

The idea is to make all characters from my NecroQuest game. I started with the succubus Tzuko. In the game Tom finds her in his basement in the middle of a summoning pentagram. She waited there a couple of month already. After she saw Tom, she tried everything from seducing him til ordering him to free her. So I gave her kinda angry pose.

I used few modeling putties to make her (mostly FIMO and green stuff) and then cast her in resin. Now everyone can get this figure (and later other characters) from Alionas online store.

As you know, Yarooze games are freeware. By buying this figure, you not only get a figurine to place it on your PC monitor, but also help me making more games. (bla-bla-bla, more propaganda for me...) (^_^)

I'll make more figurines later. If you wish your favorite character will be made next, just drop me a line. I'll try to notice your wishes. But it depends of my free time and of how successful this figure will be.


Click here for more pictures... Beware of nudity! (^_^)


2d Tzuko <-> 3d Tzuko



Tzuko on the NecroQuest Poster



Unpainted Tzuko.



I also made special base for her. (^_^)b


Size comparison. She is about 10 cm high.


"Free me! Right now!" (^_^)

Labels: , ,

Click here to see the whole post!

Wednesday, May 06, 2009

WWII girls in 1:72


 
Here is my new figure in 1:72. It had to be something WWII german, but I didn't want to make just another soldier with MP40. It makes simple more fun to sculpt girls. So here it is: Nachrichtenhelferinnen, Oberführerin, service dress.


Labels: , ,

Click here to see the whole post!

Wednesday, April 01, 2009

Silent Hill 2 for GB Arrives in April! The port of the PS2 horror-survival hit title is coming... Hurray for Konami and their long-running horror-survival series! It seems that the second installment in this series, Silent Hill, will be ported to the Game Boy after being a major hit on the PS2. Would believe if I told you that Silent Hill 2 is the reason for me buying the handheld console in the first place? The game ruled, although I have two things to comment upon it: it's way too short and it has too many locked rooms for my liking. In case you're wondering what's up with the April release date, it was spotted up on Amazon, so we can only believe the site, for now. According to a couple of rumors, Climax, the developing team who worked wonders with the first version of Silent Hill 2, will be taking up the GB version as well. In the meantime, we remind you that Silent Hill V is in the works for the NEC and Tamagotchi, promising to take the horror-survival experience to the next level. For those of you who didn't even know that there was a PlayStation (One) Silent Hill, this game will surely eat enough hours of your life to become a hobby. It serves as a sequel for the original PSP game and pretty much explains the story of the Silent Hill movie, clarifying all the mysteries. What impressed me the most in Origins, were its graphics, the vast amount of weapons I could use and the quality of the AI. I admit that it was frustrating to get killed each time I reached a new landmark, but that's life and gaming, so you'd better start training and replaying past SH titles, since this baby's coming to the GB! I'm curios if we'll see other similar ports in the future, not from Konami, but from Capcom, who haven't delivered a GBA Resident Evil title, so far, if I'm not mistaking. Original article from Softpedia’s editor Alexandru Stanescu. Published without permission. There is also a video on YouTube that demonstrates some gameplay.

Labels: , , , , ,

Click here to see the whole post!

Saturday, March 14, 2009

High elven standard bearer. There are not enough girls in the high elven army. (^_^)

After I assembled some new GW high elves, I still had spare parts. They were not enough to make the whole figure so I had to finish the model with green stuf.
I took the feet, head, dagger from the mage plastic kit, and arms & banner from the general plastic kit. Then I made the wire skeleton and put some green stuff on it. Et voilà!

Labels: ,

Click here to see the whole post!