Arduino IDE 1.8.8 Visual Studio Code 1.36.0 スケッチフォルダは自分で用意したsketchという名前のフォルダにしてある。 参考にしたスケッチのサンプルは2つ。 sketch¥generated_examples¥SerialToSerialBT¥SerialToSerialBT.ino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
//This example code is in the Public Domain (or CC0 licensed, at your option.) //By Evandro Copercini - 2018 // //This example creates a bridge between Serial and Classical Bluetooth (SPP) //and also demonstrate that SerialBT have the same functionalities of a normal Serial #include "BluetoothSerial.h" #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif BluetoothSerial SerialBT; void setup() { Serial.begin(115200); SerialBT.begin("ESP32test"); //Bluetooth device name Serial.println("The device started, now you can pair it with bluetooth!"); } void loop() { if (Serial.available()) { SerialBT.write(Serial.read()); } if (SerialBT.available()) { Serial.write(SerialBT.read()); } delay(20); } |
「ESP32 – SerialToSerialBT –」参照 sketch¥generated_examples¥01-SimpleServo¥01-SimpleServo.ino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <Servo.h> static const int servoPin = 4; Servo servo1; void setup() { Serial.begin(115200); servo1.attach(servoPin); } void loop() { for(int posDegrees = 0; posDegrees <= 180; posDegrees++) { servo1.write(posDegrees); Serial.println(posDegrees); delay(20); } for(int posDegrees = 180; posDegrees >= 0; posDegrees--) { servo1.write(posDegrees); Serial.println(posDegrees); delay(20); } } |
「ES