I am working on a project for my C programming class and need to use wiringPi on my raspberryPi. I need to create a traffic light (like a real one- red to green to yellow to red, etc.) and a pedestrian signal that turns on a white light and turns off the other colors when the button is pushed. This program is in c language and created on putty for raspberryPi.
I have the idea that:
While red is HIGH, yellow, green, and white are LOW.
While green is HIGH, yellow, red, and white are LOW.
While yellow is HIGH, red, green, and white are LOW.
If button is pushed, white is HIGH and red, yellow, green are LOW.
The order must go: red, green, yellow, red, green, yellow, red... Until the button is pushed and the white light turns on.
Once the white light turns off, the traffic light (red, green, yellow...) continues as usual.
This is my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <wiringPi.h>
int main(void)
{
// RED is pinMode 1 (18)
// YELLOW is pinMode 4 (23)
// GREEN is pinMode 5 (24)
// WHITE is pinMode 6 (25)
// SWITCH is pineMode 0 (17)
wiringPiSetup ();
pinMode (1, OUTPUT);
pinMode (4, OUTPUT);
pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
pinMode (0, INPUT);
for (;;) {
if (digitalRead(6) == LOW && digitalRead(0) == LOW) {
digitalWrite (1, LOW);
digitalWrite (4, LOW);
digitalWrite (5, LOW);
digitalWrite (6, HIGH);
delay (2000);
}
if (digitalRead(0) == LOW) {
digitalWrite (1, HIGH);
delay (1000);
digitalWrite (4, HIGH);
delay (1000);
digitalWrite (5, HIGH);
delay (1000);
digitalWrite (6, LOW);
delay (1000);
}
}
return 0;
}
No error message appears when I compile it (gcc -Wall -o student student.c -lwiringPi) (my project is named student.c) however it doesn't turn anything on and the button doesn't work either.
I have my breadboard set up right now correctly (confirmed with the professor.)
What is the problem with my code?