Traffic light toy
Recently I did for my son a traffic-light toy. Helps to study colors and traffic rules.
Now I am studying Altium that is why a traffic-light developed in it
Schematics
Board
Board in 3D
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.
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]
[/member]
No Comments