diff --git a/trafficLight/trafficLight.c b/trafficLight/trafficLight.c new file mode 100644 index 0000000000000000000000000000000000000000..afdde816bc8433c580c9d991b31e5fde88e7894f --- /dev/null +++ b/trafficLight/trafficLight.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include "pico/stdlib.h" +#include "hardware/gpio.h" + +#define RED_LED_PIN 25 +#define AMBER_LED_PIN 8 +#define GREEN_LED_PIN 7 + +int main() { + stdio_init_all(); + + + gpio_init(RED_LED_PIN); + gpio_init(AMBER_LED_PIN); + gpio_init(GREEN_LED_PIN); + + gpio_set_dir(RED_LED_PIN, GPIO_OUT); + gpio_set_dir(AMBER_LED_PIN, GPIO_OUT); + gpio_set_dir(GREEN_LED_PIN, GPIO_OUT); + + gpio_put(RED_LED_PIN, 0); + gpio_put(AMBER_LED_PIN, 0); + gpio_put(GREEN_LED_PIN, 0); + + while (true) { + + gpio_put(RED_LED_PIN, 1); + gpio_put(AMBER_LED_PIN, 0); + gpio_put(GREEN_LED_PIN, 0); + sleep_ms(20000); + + + gpio_put(RED_LED_PIN, 1); + gpio_put(AMBER_LED_PIN, 1); + gpio_put(GREEN_LED_PIN, 0); + sleep_ms(2000); + + + gpio_put(RED_LED_PIN, 0); + gpio_put(AMBER_LED_PIN, 0); + gpio_put(GREEN_LED_PIN, 1); + sleep_ms(5000); + + + gpio_put(RED_LED_PIN, 0); + gpio_put(AMBER_LED_PIN, 1); + gpio_put(GREEN_LED_PIN, 0); + sleep_ms(2000); + } + + return 0; +}