summaryrefslogtreecommitdiff
path: root/trafficlight.h
diff options
context:
space:
mode:
authorOmar Magdy <omar.professional8777@gmail.com>2022-08-25 02:24:01 +0200
committerOmar Magdy <omar.professional8777@gmail.com>2022-08-25 02:24:01 +0200
commitc3f4417efaa489c41e5d5d44fb28ae01e65ff6bc (patch)
treee64fe589fe32c39b6cdb4f81f07ca746f38c4b75 /trafficlight.h
parentbc90dfb83866078bce80034d06607b0094aa63e4 (diff)
downloadTraffic-light-c3f4417efaa489c41e5d5d44fb28ae01e65ff6bc.tar.xz
Traffic-light-c3f4417efaa489c41e5d5d44fb28ae01e65ff6bc.zip
Fixed a bug of the pedestrain traffic timer where it would restart from
5 to 1 again and Added comments for the whole project and added timers as a member of the Traffic struct to add more generlization of the
Diffstat (limited to 'trafficlight.h')
-rw-r--r--trafficlight.h39
1 files changed, 21 insertions, 18 deletions
diff --git a/trafficlight.h b/trafficlight.h
index f1f94a9..c449609 100644
--- a/trafficlight.h
+++ b/trafficlight.h
@@ -1,25 +1,16 @@
#include <stdint.h>
#include <stdbool.h>
-#include <stdlib.h>
#include "tivaware.h"
-#define TIVA_CLK 16e6
-#define GREEN_PERIOD TIVA_CLK * 5
-#define YELLOW_PERIOD TIVA_CLK * 2
-#define RED_PERIOD TIVA_CLK * 7
-#define RED 1
-#define YELLOW 2
-#define GREEN 3
+#define TIVA_CLK 16e6 //16MHz clock
+#define GREEN_PERIOD TIVA_CLK * 5 // 5 seconds
+#define YELLOW_PERIOD TIVA_CLK * 2 // 2 seconds
+#define RED_PERIOD TIVA_CLK * 7 // 7 seconds
+#define RED 1
+#define YELLOW 2
+#define GREEN 3
-typedef struct Traffic{
- uint8_t cur_color;
- uint32_t port;
- uint8_t red;
- uint8_t yellow;
- uint8_t green;
-} Traffic;
-
typedef struct Bcd{
uint32_t port;
uint8_t A;
@@ -28,21 +19,33 @@ typedef struct Bcd{
uint8_t D;
} Bcd;
+typedef struct Traffic{
+ uint8_t cur_color;
+ uint32_t port;
+ uint8_t red;
+ uint8_t yellow;
+ uint8_t green;
+ uint32_t timer;
+} Traffic;
+
extern Traffic tf1;
extern Traffic tf2;
extern Traffic tf_ped;
+
extern Bcd bcd1;
extern Bcd bcd2;
extern Bcd bcd_ped;
+
extern bool switch_pressed;
+
+
extern uint32_t period_1;
extern uint32_t period_2;
extern uint32_t period_3;
void TrafficInit();
-void Traffic_Handler(Traffic *tf, uint32_t timer);
+void Traffic_Handler(Traffic *tf);
void set_tf_color(Traffic tf, uint8_t color);
void PortInit(uint32_t port, uint32_t clk, uint32_t input, uint32_t output);
void TimerInit(uint32_t timer, void(*timer_handler)(), uint32_t clk, uint32_t delay);
void BcdWrite(Bcd bcd, uint32_t timer, bool ped);
-