Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <MFRC522.h>
- #define SS_PIN 10
- #define RST_PIN 1
- MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
- char st[20];
- volatile int passouCartao = 0;
- int carRed = 7; // estabelece o semáforo para carros
- int carYellow = 6;
- int carGreen = 5;
- int pedRed = 4; // estabelece o semáforo para pedestres
- int pedGreen = 3;
- int button = 2; // pino do botão
- int ok = 9; // está tudo OK para atravesar
- int rfidGDS = 8;
- int crossTime = 5000; //(5 segundos)
- unsigned long changeTime; // tempo desde que o botão foi pressionado
- //wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
- void interrupcao(){
- digitalWrite (rfidGDS, HIGH);
- passouCartao = 1;
- }
- void setup() {
- pinMode(ok, OUTPUT);
- pinMode(carRed, OUTPUT);
- pinMode(carYellow, OUTPUT);
- pinMode(carGreen, OUTPUT);
- pinMode(pedRed, OUTPUT);
- pinMode(pedGreen, OUTPUT);
- pinMode(rfidGDS, OUTPUT);
- pinMode(button, INPUT_PULLUP); // botão no pino 2
- digitalWrite(ok, LOW);
- // acende a luz verde (carros) e vermelha (pedestre)
- attachInterrupt(0,interrupcao,CHANGE); //Configurando a interrupção, 0 é pino 2 do UNO
- Serial.begin(9600); // Inicia a serial
- SPI.begin(); // Inicia SPI bus
- mfrc522.PCD_Init(); // Inicia MFRC522
- Serial.println("Aproxime o seu cartao do leitor...");
- Serial.println();
- }
- //wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
- void loop() {
- digitalWrite(ok, LOW);
- digitalWrite(carGreen, HIGH);
- digitalWrite(pedRed, HIGH);
- delay(5000);
- digitalWrite(carGreen, LOW);
- digitalWrite(carYellow, HIGH);
- delay(3000);
- digitalWrite(carYellow, LOW);
- digitalWrite(carRed, HIGH);
- delay(2000);
- digitalWrite(pedRed, LOW); // apaga o vermelho dos pedestres
- digitalWrite(pedGreen, HIGH); // acende o verde dos pedestres
- delay(crossTime); // espera por um intervalo de tempo predefinido (variável = 5seg)
- // pisca o verde dos pedestres
- digitalWrite(pedGreen, LOW);
- for (int x=0; x<10; x++) {
- digitalWrite(pedRed, HIGH);
- delay(250);
- digitalWrite(pedRed, LOW);
- delay(250);
- digitalWrite(pedGreen, LOW);
- }
- // acende o vermelho dos pedestres
- digitalWrite(pedRed, HIGH);
- delay(1000);
- digitalWrite(carRed, LOW);
- if (passouCartao == 1){
- dezSeg();
- }
- }
- void dezSeg() {
- digitalWrite(ok, HIGH);
- digitalWrite(carGreen, HIGH);
- digitalWrite(pedRed, HIGH);
- delay(5000);
- digitalWrite(carGreen, LOW);
- digitalWrite(carYellow, HIGH);
- delay(3000);
- digitalWrite(carYellow, LOW);
- digitalWrite(carRed, HIGH);
- delay(2000);
- digitalWrite(pedRed, LOW); // apaga o vermelho dos pedestres
- digitalWrite(pedGreen, HIGH); // acende o verde dos pedestres
- delay(15000); // espera por um intervalo de tempo predefinido (variável = 5seg)
- // pisca o verde dos pedestres
- digitalWrite(pedGreen, LOW);
- for (int x=0; x<10; x++) {
- digitalWrite(pedRed, HIGH);
- delay(250);
- digitalWrite(pedRed, LOW);
- delay(250);
- digitalWrite(pedGreen, LOW);
- }
- // acende o vermelho dos pedestres
- digitalWrite(pedRed, HIGH);
- delay(1000);
- digitalWrite(ok, LOW);
- digitalWrite(rfidGDS, LOW);
- delay(250);
- digitalWrite(rfidGDS, HIGH);
- delay(250);
- digitalWrite(rfidGDS, LOW);
- delay(250);
- digitalWrite(rfidGDS, HIGH);
- delay(250);
- digitalWrite(rfidGDS, LOW);
- digitalWrite(carRed, LOW);
- // registra o tempo desde a última alteração no semáforo
- changeTime = millis();
- // depois retorna para o loop principal do programa
- passouCartao = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement