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 buzzerPin 2 //ブザーが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
//時計回りのモーターが、ボタンを押すと、反時計回りになるプログラム | |
#include <Servo.h> | |
#define motorPin 3 | |
#define buttonPin 12 | |
int 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
//ボタンを押すと、モーターが回り、もう一度、ボタンを押すとモーターが止まるプログラム。(スイッチON、OFFで必要なプログラムは//でマークをつけています。) | |
#include <Servo.h> | |
#define motorPin 3 | |
#define buttonPin 12 //スイッチON、OFF | |
int buttonState = 0; //スイッチON、OFF | |
Servo myservo; |
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秒間右回転し、3秒間左回転しLEDもつくプログラム | |
#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
// 距離20㎝以下でなおかつ電気を消すとLEDが光り、モーターが回る | |
#include <Servo.h> //モーターを使うときは、これを入れます。 | |
#define cdsPin 1 //光センサーが11番ピン | |
#define echoPin 11 //距離センサーの「echo」が11番ピン | |
#define trigPin 12 //距離センサーの「trig」が12番ピン | |
#define ledPin 2 //LED2番ピン |
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 11 //距離センサーの「echo」が11番ピン | |
#define trigPin 12 //距離センサーの「trig」が12番ピン | |
#define buzzerPin 2 //ブザーが2番ピン | |
#define moterPin 3 //モーターが3番ピン |
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
//10センチよりちかくなったら、遅く回転していたモーターが回るのをやめ、明かりがつくプログラム | |
#include <Servo.h> //サーボモーターを動かす関数を用意します | |
#define echoPin 11 //5を11に変更 | |
#define trigPin 12 //6を12に変更。この2つで、距離センサーの準備をします。 | |
#define cdsPin 1 //スイッチの文章を消して、光センサーの文章に変えます。このとき、数値は1番ピンにさしたので1になります。 |
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
//電源を入れると前進し、障害物から15cm離れたところで停止する車のプログラム | |
#include <Servo.h> //サーボモーターを動かす関数を用意します | |
#define moterPinR 2 | |
#define moterPinL 3 | |
#define echoPin 11 | |
#define trigPin 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
// ある程度明るいと車が前進、障害物を避ける。暗いと停止。 | |
#include <Servo.h> //サーボモーターを動かす関数を用意します | |
#define cdsPin 1 | |
#define moterPinR 2 | |
#define moterPinL 3 |