BASIC4MCU | 질문게시판 | 답변 : 아두이노 인터럽트
페이지 정보
작성자 master 작성일2019-11-24 09:47 조회4,981회 댓글1건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=10849
본문
// MCU BASIC: https://www.basic4mcu.com// DateTime : 2019-11-24 오전 9:47:00// by Ok-Hyun Park//#include <LiquidCrystal_I2C.h>#include <Wire.h>LiquidCrystal_I2C lcd(0x27,16,2);//#include <SPI.h>#include <MFRC522.h>const int RST_PIN=9,SS_PIN=10;MFRC522 mfrc522(SS_PIN,RST_PIN);//#include <SoftwareSerial.h>SoftwareSerial BTSerial(0,1);//#include <Servo.h>Servo servo;//const int SERVO_PIN=8,TONEPIN=5;const int LEDB=7,LEDR=6;const int TRIG_PIN=3,ECHO_PIN=2;//byte cardkeyByte[4]={0xE9,0x85,0x59,0x98};bool state=false;bool status=0;//void setup(){Serial.begin(9600);BTSerial.begin(9600);while(!Serial);SPI.begin();mfrc522.PCD_Init();Serial.println(F("Warning: this example clears your mifare UID,use with care!"));pinMode(TRIG_PIN,OUTPUT); pinMode(ECHO_PIN,INPUT);pinMode(LEDR,OUTPUT); pinMode(LEDB,OUTPUT);servo.attach(SERVO_PIN); servo.write(0);lcd.init();lcd.backlight();delay(50);}//void loop(){if(mfrc522.PICC_IsNewCardPresent()){if(mfrc522.PICC_ReadCardSerial()){if(!memcmp(mfrc522.uid.uidByte,cardkeyByte,4)){tone(TONEPIN,523,1000/8); delay(1000/4*1.30); noTone(TONEPIN);status^=1;}}}//digitalWrite(TRIG_PIN,HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN,LOW);float duration=pulseIn(ECHO_PIN,HIGH);float distance=duration/57.5;//if(status){if(distance<10){digitalWrite(LEDR,LOW); digitalWrite(LEDB,HIGH);lcd.setCursor(4,0); lcd.print("Warning!");lcd.setCursor(0,1); lcd.print(" please call 112");Serial.print("Close: "); Serial.println(distance);noTone(TONEPIN); tone(TONEPIN,3700); if(myDelay(325))return;noTone(TONEPIN); tone(TONEPIN,3900); if(myDelay(325))return;noTone(TONEPIN); tone(TONEPIN,3700); if(myDelay(325))return;noTone(TONEPIN); tone(TONEPIN,3900); if(myDelay(325))return;noTone(TONEPIN); servo.write(0);}else{digitalWrite(LEDB,HIGH); digitalWrite(LEDR,LOW);lcd.init();lcd.setCursor(4,0); lcd.print("Safety");lcd.setCursor(0,1); lcd.print("Have a good time");Serial.println("Open"); servo.write(180);}}//delay(100);}//int myDelay(int d){for(int i=0; i<d; i++){if(mfrc522.PICC_IsNewCardPresent())return 1;delay(1);}return 0;}
댓글 1
조회수 4,981hello님의 댓글
hello 작성일감사합니다~!!! 잘됩니단~!!