Why Arduino can't recognize my Arduino Mega 2560?
Would you care to expand on that (a lot) !
There is not enough information to give any sort of answer.
/* Three Colour Traffic Light With Barrier*/
// Number of pins connected to Traffic leds :
const int traffic_red = 12;
const int traffic_orange= 11;
const int traffic_green = 10;
// Number of pins connected to Pedestrian leds:
const int pedestrian_red = 9;
const int pedestrian_green= 8 ;
// The number of push button pin :
const int button_pin = 2;
// Variable for reading the push button state:
int button_state = 0;
// Setup loop will run once:
void setup()
{
// Initializing traffic leds as an output:
pinMode(traffic_red , OUTPUT );
pinMode(traffic_orange , OUTPUT );
pinMode(traffic_green , OUTPUT );
// Initializing pedestrian leds as an output:
pinMode(pedestrian_red , OUTPUT ); pinMode(pedestrian_green ,OUTPUT );
// Initializing push button pin as an input:
pinMode(button_pin , INPUT );
}
// void loop will run repeatedly:
void loop()
{
// Read the state of button_pin :
button_state=digitalRead(button_pinn);
// If the push button is pressed then button_state is equal to HIGH and if block will execute:
if(button_state ==HIGH )
{
digitalWrite( traffic_green , HIGH); // Green light of traffic will glow:
digitalWrite(pedestrian_red , HIGH); // Red light of pedestrian light will also glow:
delay(3000); // These lights glow for 3 seconds:
digitalWrite( traffic_green , LOW); // Green light of traffic will turn off:
digitalWrite( traffic_orange , HIGH);// Orange light of traffic will glow:
delay(1000); // Orange light will glow for 1 second:
digitalWrite( traffic_orange , LOW); // Orange light will turn off:
digitalWrite( pedestrian_red, LOW);// Red light of pedestrian will turn off:
digitalWrite( traffic_red , HIGH);// Red light of traffic will glow:
digitalWrite( pedestrian_green , HIGH); // Green light of pedestrian will glow:
delay(5000); // Both lights will glow for 5 seconds:
digitalWrite( traffic_red , LOW); // Red light of traffic will turn off:
digitalWrite (pedestrian_green, LOW); // Green light of pedestrian will turn off:
}
// If the push button is not pressed,then else block will execute:
else{
digitalWrite( traffic_green , HIGH); // Green light of traffic will glow:
delay(3000); // Green light will glow for 3 seconds:
digitalWrite(traffic_green , LOW); // Green light will turn off:
digitalWrite( traffic_orange , HIGH);// Orange light of traffic will glow;
delay(1000); // Light will glow for 1 second:
digitalWrite(traffic_orange , LOW); // Orange light will turn off:
digitalWrite( traffic_red , HIGH);// Red light of traffic will glow:
delay(3000); // Light will glow for 3 seconds:
digitalWrite(traffic_red , LOW); // Red light of traffic will turn off:
}
}
better use
const byte instead of const int
and
bool button_state instead of int button_state