I'm working on a traffic light simulation project using an Atmega16 microcontroller, and I'm facing some issues with the code. I have four traffic lights positioned in the north, south, west, and east directions on a map. Each traffic light is controlled using specific pins on the microcontroller.
Here are the pin assignments for each traffic light:
- The North traffic light uses PB0/X0/XCK, PB1/T1 and PB2/AIN0/INT2 pins.
- The West traffic light uses PD1/TXD, PD2/INT0 and PD3/INT1 pins.
- The South traffic light uses PB6/MISO, PB7/SCK and PD0/RXD pins.
- The East traffic light uses PB3/AIN1/OC0, PB4/SS and PB5/MOSI pins.
The sample code here, which i'm gonna send, demonstrates the clockwise cycle between the traffic lights starting from the top (north, then east, then south, and west, and so on).
The original traffic light code works like this:
/*
* GccApplication9.c
* Traffic Light
* Created: 9/22/2023 6:39:24 PM
* Author : hp
*/
#define F_CPU 1000000UL
#include<avr/io.h>
#include<util/delay.h>
int main()
{
DDRB=0XFF;
DDRD=0XFF;
while(1)
{
PORTB=0b01001100;
PORTD=0b00000010;
_delay_ms(4000);
PORTB=0b01010010;
PORTD=0b00000010;
_delay_ms(1500);
PORTB=0b01100001;
PORTD=0b00000010;
_delay_ms(4000);
PORTB=0b10010001;
PORTD=0b00000010;
_delay_ms(1500);
PORTD=0b00000011;
PORTB=0b00001001;
_delay_ms(4000);
PORTB=0b10001001;
PORTD=0b00000100;
_delay_ms(1500);
PORTD=0b00001000;
PORTB=0b01001001;
_delay_ms(4000);
PORTD=0b00000100;
PORTB=0b01001010;
_delay_ms(1500);
}
}
My goal is making the traffic lights located parallel to each other would light up with the same color (e.g. both were green) when the other two were the opposite color (if the first two start to light up green, then the remaining two should light up red).
This is schematic.
And I've tried to change the numbers on the ports, but nothing worked.