summaryrefslogtreecommitdiff
path: root/color.c
diff options
context:
space:
mode:
authorOmar Magdy <omar.professional8777@gmail.com>2022-08-23 12:32:39 +0200
committerOmar Magdy <omar.professional8777@gmail.com>2022-08-23 12:32:39 +0200
commitb5c1df30961369762e6c9ead8a11f8c9d0f5f8a3 (patch)
tree3f2f6583b0b302d56ab88ef476f1c4fcbce510b2 /color.c
parent5a180583b8835b564d519c8a2548edc92a01842e (diff)
downloadTraffic-light-b5c1df30961369762e6c9ead8a11f8c9d0f5f8a3.tar.xz
Traffic-light-b5c1df30961369762e6c9ead8a11f8c9d0f5f8a3.zip
Added two timers and made them sync the 2 traffic lights as when one
traffic light is green the other is red and vice versa.
Diffstat (limited to 'color.c')
-rw-r--r--color.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/color.c b/color.c
index 9806979..e7e072d 100644
--- a/color.c
+++ b/color.c
@@ -3,42 +3,46 @@
void set_color(uint8_t color) {
+ uint32_t pins = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6;
switch (color) {
- case RED:
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0x2);
+ case RED_TF1:
+ GPIOPinWrite(GPIO_PORTF_BASE, pins, 0x2);
break;
- case BLUE:
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0x4);
+ case YELLOW_TF1:
+ GPIOPinWrite(GPIO_PORTF_BASE, pins, 0x4);
break;
- case GREEN:
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0x8);
+ case GREEN_TF1:
+ GPIOPinWrite(GPIO_PORTF_BASE, pins, 0x8);
break;
- case YELLOW:
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0xA);
+ case RED_TF2:
+ GPIOPinWrite(GPIO_PORTA_BASE, pins, 0x4);
break;
- case WHITE:
- GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3, 0xe);
+ case YELLOW_TF2:
+ GPIOPinWrite(GPIO_PORTA_BASE, pins, 0x8);
break;
- }
-}
-
-void toggle_color(uint8_t color) {
- switch (color) {
- case RED:
- GPIO_PORTF_DATA_R ^= LED_RED;
- break;
- case BLUE:
- GPIO_PORTF_DATA_R ^= LED_BLUE;
- break;
- case GREEN:
- GPIO_PORTF_DATA_R ^= LED_GREEN;
- break;
- case WHITE:
- GPIO_PORTF_DATA_R ^= (LED_RED | LED_BLUE | LED_GREEN);
+ case GREEN_TF2:
+ GPIOPinWrite(GPIO_PORTA_BASE, pins, 0x10);
break;
}
}
+// void toggle_color(uint8_t color) {
+// switch (color) {
+// case RED:
+// GPIO_PORTF_DATA_R ^= LED_RED;
+// break;
+// case BLUE:
+// GPIO_PORTF_DATA_R ^= LED_BLUE;
+// break;
+// case GREEN:
+// GPIO_PORTF_DATA_R ^= LED_GREEN;
+// break;
+// case WHITE:
+// GPIO_PORTF_DATA_R ^= (LED_RED | LED_BLUE | LED_GREEN);
+// break;
+// }
+// }
+
void reset_color() {
PORTF &= 0x11;
}