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をシリアルモニターに表示するプログラム | |
#define buttonPin 12 | |
int buttonState = 0; | |
void setup() { | |
Serial.begin(9600); |
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
// 光量値を示すプログラム(10kΩプルダウン、5V電源時) | |
#define cdsPin 1 | |
void setup() { | |
Serial.begin(9600); | |
pinMode(cdsPin, 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
//時計回りのモーターが、ボタンを押すと、反時計回りになるプログラム | |
#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
// ある程度明るいと車が前進、障害物を避ける。暗いと停止。 | |
#include <Servo.h> //サーボモーターを動かす関数を用意します | |
#define cdsPin 1 | |
#define moterPinR 2 | |
#define moterPinL 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
// 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
// 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
// 距離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
//ボタンを押すと、モーターが回り、もう一度、ボタンを押すとモーターが止まるプログラム。(スイッチON、OFFで必要なプログラムは//でマークをつけています。) | |
#include <Servo.h> | |
#define motorPin 3 | |
#define buttonPin 12 //スイッチON、OFF | |
int buttonState = 0; //スイッチON、OFF | |
Servo myservo; |
OlderNewer