Question: I am designing a traffic control program using Atmel Studio and programming in C. I want to know what would be the best way to

I am designing a traffic control program using Atmel Studio and programming in C. I want to know what would be the best way to go about this.

There are cars moving NS and EW. I want to the program to change the lights depending on if cars are detected in either directions(EW or NS).

I don't want the code, I just want to know the best way to do this. See my code I have done so far and let me know if I am on the right path. If not, let me know what I should be doing.

/* * Traffic_Lights.c * * Created: 08/01/2020 7:25:31 PM * Author : Mike */ /* There are 2 states, NSGreen and EWGreen*/

#include "samd21.h" /*Set traffic lights */ #define Red_Light 8 #define Yellow_Light 9 #define Green_Light 10

/* Set sensor inputs*/ #define NSCar PA05 #define EWCar PA04

/* Set control signal outputs */ #define NSLite PB00 #define EWLite PB06

void NSCar(void); void EWCar(void);

int main(void) {

unsigned char* ARRAY_PORT_PINCFG0 = (unsigned char*) ®_PORT_PINCFG0;

/*Set lights as outputs on Port A */ REG_PORT_DIRSET0 = (1 << 8); REG_PORT_DIRSET0 = (1 << 9); REG_PORT_DIRSET0 = (1 << 10);

/*Set car sensors as inputs on Port B */ REG_PORT_DIRCLR1 = (1 << 0); REG_PORT_DIRCLR1 = (1 << 6);

/*Initialize all lights as off */ int Red_ = 0; int Yellow = 0; int Green = 0;

/* Replace with your application code */ while (1) { } }

/* When a car is detected in the NS direction INPUT */ void NSCar(void){

REG_PORT_OUTCLR0 = 1 << Green_Light;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!