Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sb612a.cpp
00001 //************************************************** 00002 // 00003 // sb612a.cpp 00004 // 焦電センサー 00005 // 00006 //************************************************** 00007 #include "mbed.h" 00008 #include "sb612a.h" 00009 00010 int pinNum; //各ピン番号用の変数 00011 int pirSensor = 2; //焦電センサを2番ピン 00012 int pushSwitch = 3; //PUSHスイッチを3番ピン 00013 00014 void setup() 00015 { 00016 //4番ピン~13番ピンをOUTPUTに設定 00017 for (pinNum = 4; pinNum < 14; pinNum++) { 00018 pinMode(pinNum, OUTPUT); 00019 } 00020 pinNum = 4; //最初は4番ピンのLEDから点灯 00021 00022 pinMode(pirSensor, INPUT); 00023 pinMode(pushSwitch, INPUT_PULLUP); //内蔵のプルアップ抵抗を有効にしています。 00024 //焦電センサの出力をトリガーに割り込み信号出力 00025 attachInterrupt(digitalPinToInterrupt(pirSensor), ledControl, RISING); 00026 } 00027 00028 void loop() {} 00029 00030 //---LEDの点灯--------------------------- 00031 void ledControl() 00032 { 00033 int pirLevel; //PUSHスイッチの値を格納する変数 00034 00035 pirLevel = digitalRead(pirSensor); 00036 if (pirLevel == HIGH) { 00037 while (1) { 00038 for (pinNum = 4; pinNum < 13; pinNum++) { 00039 digitalWrite(pinNum, HIGH); 00040 delay(2000); 00041 digitalWrite(pinNum, LOW); 00042 delay(2000); 00043 } 00044 for (pinNum = 13 ; pinNum > 4; pinNum--) { 00045 digitalWrite(pinNum, HIGH); 00046 delay(2000); 00047 digitalWrite(pinNum, LOW); 00048 delay(2000); 00049 } 00050 00051 int switchLevel; //PUSHスイッチの値を格納する変数 00052 00053 //スイッチが押されたらループを抜ける 00054 switchLevel = digitalRead(pushSwitch); 00055 if (switchLevel == LOW) { 00056 break; 00057 } 00058 } 00059 } 00060 } 00061 00062 //別のプログラム↓ 00063 void setup() 00064 { 00065 pinMode(15, INPUT); 00066 pinMode(16, OUTPUT); 00067 } 00068 00069 void loop() 00070 { 00071 if (digitalRead(7) == HIGH) { 00072 digitalWrite(13, HIGH); 00073 delay(5000); 00074 } else { 00075 digitalWrite(13, LOW); 00076 } 00077 }
Generated on Wed Aug 17 2022 08:27:39 by
 1.7.2
 1.7.2