This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 電気が消え、かつスイッチが押されるとLEDがつく → 電気が消え、スイッチが押されなかったらLEDが消える に変更する | |
#define cdsPin 1 //光センサーが1番ピンに入っています。 | |
#define buttonPin 12 //スイッチが12番ピンに入っています。 | |
#define ledPin 2 //LEDが2番ピンに入っています。 | |
bool buttonState = 0;//スイッチがあるときはこれをいれます。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 15センチ以上で、スイッチが押されると、モーターが回転し、ブザーが鳴るプログラム | |
#include <Servo.h> //サーボモーターを動かす関数を用意します | |
#define echoPin 5 //D5に、ピンが入っている。これが1つめのINPUT※距離センサー | |
#define trigPin 6 //D6に、ピンが入っている。これが1つめのINPUT※距離センサー | |
#define buttonPin 12 //これが2つめのINPUT※スイッチ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 15センチ以上だと、モーターが5秒間右回転するプログラム | |
#include <Servo.h> //サーボモーターを動かす関数を用意します | |
#define moterPin 3 //モーターが3番ピン | |
#define echoPin 11 //距離センサーの「echo」が11番ピン | |
#define trigPin 12 //距離センサーの「trig」が12番ピン |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 距離10cmより近づくとブザーが鳴るプログラム | |
#define buzzerPin 9 //ブザーが9番ピン | |
#define echoPin 11 //距離センサーの「echo」が11番ピン | |
#define trigPin 12 //距離センサーの「trig」が12番ピン | |
double Duration = 0; //受信した間隔 | |
double Distance = 0; //距離 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 距離10cmより近いとLEDかブザーのどちらかが反応する(ランダム) | |
#define ledPin 2 //LEDが2番ピン | |
#define buzzerPin 6 //ブザーが6番ピン | |
#define echoPin 11 //距離センサーの「echo」が11番ピン | |
#define trigPin 12 //距離センサーの「trig」が12番ピン | |
double Duration = 0; //受信した間隔 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 距離10cmより離れてて、20cmより近いとき、スイッチが押されるとどちらかのLEDがつく(ランダム) | |
#define ledPin1 2 //LED1が2番ピン | |
#define ledPin2 3 //LED2が3番ピン | |
#define echoPin 5 //距離センサーの「echo」が5番ピン | |
#define trigPin 6 //距離センサーの「trig」が6番ピン | |
double Duration = 0; //受信した間隔 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// はじめライトは消えていて、距離20㎝以下でなおかつ電気を消すとライトがつく。 | |
#define cdsPin 1 //光センサーが1番ピンに入っています。 | |
#define echoPin 11 //距離センサーの「echo」が11番ピン | |
#define trigPin 12 //距離センサーの「trig」が12番ピン | |
#define ledPin 2 //LEDが2番ピン | |
double Duration = 0; //受信した間隔 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 距離20㎝以下でなおかつ電気を消すとモーターが回る | |
#include <Servo.h> //モーターを使うときは、これを入れます。 | |
#define cdsPin 1 //光センサーが11番ピン | |
#define echoPin 11 //距離センサーの「echo」が11番ピン | |
#define trigPin 12 //距離センサーの「trig」が12番ピン | |
#define motorPin 3 //モーターが12番ピン |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 電気が消え、かつスイッチが押されるとブザーが鳴る | |
#define cdsPin 1 //光センサーが1番ピン | |
#define buttonPin 12 //スイッチが12番ピン | |
#define buzzerPin 2 //LEDが2番ピン | |
bool buttonState = 0; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 電気が消え、かつスイッチが押されるとモーターがまわる | |
#define cdsPin 1 //光センサーが1番ピン | |
#define buttonPin 12 //スイッチが12番ピン | |
#include <Servo.h> //サーボモーターを動かす関数を用意します | |
#define moterPin 3 //モーターが3番ピン | |
bool buttonState = 0; |