Archived Geocache GC3QFRD (Hot Wire)

"Gaming in the Woods - Hot Squirrel"

 

The technical stages of this geocache disappeared several times I decided to archive this cache.

Because there has been a lot of effort in developing this cache I thought it might be interesting for the croud to see what's inside the box.

 

First assembling on the breadboard

The first step was to put everything together on the breadboard and check if I realize what I had in mind.

 

 

Drawing the PCB for the project

This was one of my first projects. This PCB has been drawn in a graphics tool.

My later PCBs are made with Eagle.

 

 

Putting everything in a nice frame

After the PCB was ready and the breadboard constellation worked, it was time to put everything in a nice frame.

It was a challenge too, to bend the copper in the outlines of a squirrel. (But finally it worked.)

 

 

Writing the code

With programming the ATMega168 the parts would not do a thing.

As power supply I used a 9V battery.

Here you can see the tiny and simple code which I used for that cache.

 

Main Program

View source
// hot_wire.c
// for NerdKits with ATmega168
 
#define F_CPU 14745600
 
#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#include <string.h>
 
#include "../libnerdkits/lcd.h"
#include "../mylibs/7segment.c"
 
#define D5 851
#define E5 758
#define Fsh5 675
#define G5 637
#define A5 568
#define B5 506
#define C6 477
#define D6 425
#define DUR 40
 
#define Csh6 450
#define Gsh5 601
 
// PIN DEFINITIONS:
 
// #### 7 Segment Anzeige ###
// ---------------------------------
// PC4 -- LED (g)  7 Segment Kathode
// PC3 -- LED (f)  7 Segment Kathode
// PC2 -- LED (e)  7 Segment Kathode
// PC1 -- LED (a)  7 Segment Kathode
// PC0 -- LED (b)  7 Segment Kathode
 
// PD2 -- LED (d)  7 Segment Kathode
// PD3 -- LED (DP) 7 Segment Kathode
// PD4 -- LED (c)  7 Segment Kathode
 
 
// ### Other LEDs ###
// ------------------
// PB2 -- LED Red
// PB4 -- LED Green
 
// ### Piezzo ###
// --------------
// PB3 -- Piezo Buzzer
 
// Prototypes
void spinning_7_segment();
void play_tone(uint16_t, uint8_t);
 
// Global Variables
volatile int32_t start;
volatile int32_t finish;
 
 
int main(void) {
 
	// internal RC oscillator calibration for 8MHz.
	OSCCAL = 176;
 
	DDRC  = 0b11011111; // Pinc.0,1,2,3,4 as Output, the Rest as Input
	DDRD  = 0b01111111; // Pind.2,3,4 as Output, the Rest as Input
	DDRB  = 0b11111101; // Pinb.0,2,3,4,5  as Output, the Rest as Input
 
	// PB1,PD7,PC5 als Input
	DDRD &= ~(1<<PD7);
	DDRC &= ~(1<<PC5);
	DDRB &= ~(1<<PB1);
 
  	// turn on the internal resistors for the pins
	PORTD |= (1<<PD7); // turn on internal pull up resistor
	PORTC |= (1<<PC5); // turn on internal pull up resistor
	PORTB |= (1<<PB1); // turn on internal pull up resistor
 
	// Start Settings
	clear_segment();			// Clear 7 Segment Display
	PORTB |= (1<<PB4);			// Turn On Green LED
 
  while(1) {
 
	while(!(PINC & (1<<PC5))) 		// When Wire is touched
	{
		PORTB |= (1<<PB2);			// Turn On Red LED
		PORTB &= ~(1<<PB4);		// Turn Off Green LED
		_delay_ms(120);				// Debouncing
		play_tone(Fsh5, 2*DUR);
		start = 0;
		finish = 0;
	}
 
	while(!(PIND & (1<<PD7))) 		// When Start is touched
	{
		PORTB |= (1<<PB4);			// Turn On Green LED
		PORTB &= ~(1<<PB2);		// Turn Off Red LED	
		_delay_ms(120);				// Debouncing
		start = 1;
	}
 
	while(!(PINB & (1<<PB1))) 		// When Finish is touched
	{
		PORTB |= (1<<PB4);			// Turn On Green LED
		PORTB &= ~(1<<PB2);		// Turn Off Red LED	
		_delay_ms(120);				// Debouncing
		finish = 1;
	}
 
	if(start == 1 && finish == 1)
	{	
		while(1)
		{
			// Output of the final coordinates
			segment('4');
			segment('7');
			segment('.');
			segment('1');
			segment('4');
			segment('.');
			segment('9');
			segment('2');
			segment('6');
			segment('.');
			segment('1');
			short_break();
			segment('1');
			segment('.');
			segment('2');
			short_break();
			segment('2');
			segment('.');
			segment('0');
			segment('1');
			segment('6');
		}
	}
 
	else
	{}
 
  }
  return 0;
}
 
void play_tone(uint16_t delay, uint8_t duration) {
  // delay is half-period in microseconds
  // duration is in 10ms increments
 
  // example: 440Hz --> delay=1136
 
 
  // duration = 2*delay * cycles (all in same units)
  // cycles = 10000 * duration / delay / 2
  // cycles = 100 * duration / (delay/50)
  uint16_t tmp = 100 * duration;
  uint16_t delaysm = delay / 50;
  uint16_t cycles = tmp / delaysm;
 
  while(cycles > 0) {
    PORTB |= (1<<PB3);
    delay_us(delay);
    PORTB &= ~(1<<PB3);
    delay_us(delay);
    cycles--;
  }
}
 
 
void spinning_7_segment() {			// Spinning optic of the 7 Segment Display
 
	int i;
 
	for(i=0; i<5; i++){
		clear_segment();
		PORTC = 0b11111101;
		_delay_ms(50);
		clear_segment();
		PORTC = 0b11111110;
		_delay_ms(50);
		clear_segment();
		PORTD = 0b11101111;
		_delay_ms(50);
		clear_segment();
		PORTD = 0b11111011;
		_delay_ms(50);
		clear_segment();
		PORTC = 0b11111011;
		_delay_ms(50);
		clear_segment();
		PORTC = 0b11110111;
		_delay_ms(50);
		clear_segment();
	}
}