Traffic light toy

Recently I did for my son a traffic-light toy. Helps to study  colors  and traffic rules.

CAM00474

 

Now I am  studying Altium that is why a traffic-light developed in it

Schematics

2015-02-10_142500

Board

2015-02-10_143015

Board in 3D

2015-02-10_142536

 

Code

#include <avr/io.h>

#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/sleep.h> 



#define YELLOW_on PORTB |= (1<<PB4);
#define YELLOW_off PORTB &= ~(1<<PB4);
#define YELLOW_toggle PORTB ^= PB4;

#define RED_on PORTB |= (1<<PB3);
#define RED_off PORTB &= ~(1<<PB3);
#define RED_toggle PORTB ^= PB3;

#define GREEN_on PORTB |= (1<<PB2);
#define GREEN_off PORTB &= ~(1<<PB2);
#define GREEN_toggle PORTB ^= (1<<PB2);


unsigned char Sec = 0;
unsigned char MSec = 0;





void gpio_init(void)
{

	DDRB &= ~(1<<PB2); //input
	PORTB |= (1<<PB2); //pullup


	DDRB |= (1<<PB4); //output
	PORTB &= ~(1<<PB4); //off

	DDRB |= (1<<PB3); //output
	PORTB &= ~(1<<PB3); //off
		
	DDRB |= (1<<PB1); //output
	PORTB &= ~(1<<PB1); //off

	DDRB |= (1<<PB0); //output
	PORTB &= ~(1<<PB0); //off

}




//*************************** MAIN *******************************//
int main(void)
{
	gpio_init();

	while(1)
	{


		_delay_ms(100);
		
		if (MSec>7)
		{
			MSec=0;
			
			if(Sec>60)
			{
				Sec=0;
			}
			else
			{
				Sec++;
			}
		}
		else
		{
			MSec++;
		}
		
		switch (Sec)
		{
		case 0:
			RED_on;
			YELLOW_off;
			GREEN_off;
			break;

		case 10:
			RED_on;
			YELLOW_on;
			GREEN_off;
			break;
		
		case 14:
			RED_off;
			YELLOW_off;
			GREEN_on;
			break;
		
		case 20:
			RED_off;
			YELLOW_off;
			GREEN_off;
			break;

		case 21:
			RED_off;
			YELLOW_off;
			GREEN_on;
			break;

		case 22:
			RED_off;
			YELLOW_off;
			GREEN_off;
			break;

		case 23:
			RED_off;
			YELLOW_off;
			GREEN_on;
			break;
		
		case 24:
			RED_off;
			YELLOW_off;
			GREEN_off;
			break;
		
		case 25:
			RED_off;
			YELLOW_on;
			GREEN_off;
			break;

		case 29:
			Sec=0;
			break;									
		
		default:
			break;

		}

	}

}

A case lasercut out from 3.85mm plywood glued together and painted.
CAM00479
2015-02-10_144726
CAM00474
A board is in overhead part, light-emitting diodes are covered a dispersive plastic. At a bottom 2 batteries of AAA  in holder and swich are placed.

Video of work.

Files of project of Altium, code of Avrstudio, draft of Coreldraw

[member]

Traffic Light

[/member]

Leave a Reply