Descrierea schemei electronice:
-terminalele pozitive ale celor 3 leduri(anodul) se conecteaza pe rand la pinii digitali 2 ,3 ,4 iar terminalele negative(catodul) se leaga printr-o rezistenta de 270 de ohmi la GND.
-un terminal al intrerupatorului se conecteaza la pinul analogic ''5v'' iar celalalt terminal se conecteaza printr-o rezistenta de 100kohmi la GND.
Vom seta pinii placutei arduino astfel:
-pinii 2,3,4 digitali-ca iesiri;
-pinul 5 digital(care defineste starea intrerupatorului) ca pin de intrare.
CODUL SURSA(sketch-ul):
//program SEMAFOR
int redPin=2;
int yellowPin=3;
int greenPin=4;
int buttonPin=5;
int state=0;
void setup(){
pinMode(redPin,OUTPUT);
pinMode(yellowPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(buttonPin,INPUT);
}
void loop(){
if(digitalRead(buttonPin)){
if(state==0){oscilare(HIGH,LOW,LOW);
state=1;
}
else if(state==1){
oscilare(HIGH,HIGH,LOW);
state=2;
}
else if(state==2){
oscilare(LOW,LOW,HIGH);
state=3;
}
else if(state==3){
oscilare(LOW,HIGH,HIGH);
state=0;
}
delay(1000);}
}
void oscilare(int red,int yellow,int green){
digitalWrite(redPin,red);
digitalWrite(yellowPin,yellow);
digitalWrite(greenPin,green);
}
Blogger templates
Archives
About
Persoane interesate
Categories
- arduino (8)
- Electronica Digitala (1)
- Java/Android (1)
- matlab (1)
- MSP 430 (1)