You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
#include <Arduino.h>
|
|
#include <BluetoothSerial.h>
|
|
|
|
#define LED_PIN 2
|
|
|
|
String device_name = "ESP-PWM-Skrabanek";
|
|
BluetoothSerial SerialBT;
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
SerialBT.begin(device_name);
|
|
pinMode(LED_PIN,OUTPUT);
|
|
Serial.println("Bluetooth PWM projekt spusten.");
|
|
Serial.println("Prikazy: 'jas:X' (kde X je 0-255)");
|
|
}
|
|
|
|
void loop() {
|
|
if (SerialBT.available()){
|
|
String input = SerialBT.readStringUntil('\n');
|
|
input.trim();
|
|
input.toLowerCase();
|
|
|
|
if(input.startsWith("jas:")){
|
|
//potřeba získat část za dvojtečkou
|
|
String valueStr = input.substring(4);
|
|
int value = valueStr.toInt(); //převod na celé číslo
|
|
//omezení hodnoty na 0-255
|
|
value = constrain(value,0,255);
|
|
analogWrite(LED_PIN,value);
|
|
SerialBT.print("Jas nastaven na:");
|
|
SerialBT.println(value);
|
|
Serial.printf("BT: Nastaven jas na %d \n",value);
|
|
} else if (input == "vypnout") {
|
|
analogWrite(LED_PIN,0);
|
|
SerialBT.println("LED vypnuta");
|
|
} else {
|
|
SerialBT.println("neznamy prikaz");
|
|
}
|
|
}
|
|
}
|
|
|