Add slider to control led intensity [ESP]
2 posters
Page 1 of 1
Add slider to control led intensity [ESP]
Hi,
I'm trying to control the led with roboremo and I need to add slider which controls led intensity and a button. I borrowed button's code (c) from one of roboremo projects but I cannot understand how to add a slider (in code) which controls ledIntensity value from 0 to 255. Any simple example?
I'm using ESP-07 for that and uploading the code via ArduinoIDE with UART adapter.
Here's the code:
I'm trying to control the led with roboremo and I need to add slider which controls led intensity and a button. I borrowed button's code (c) from one of roboremo projects but I cannot understand how to add a slider (in code) which controls ledIntensity value from 0 to 255. Any simple example?
I'm using ESP-07 for that and uploading the code via ArduinoIDE with UART adapter.
Here's the code:
- Code:
// Disclaimer: Don't use RoboRemo for life support systems
// or any other situations where system failure may affect
// user or environmental safety.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <Servo.h>
// config:
const char *ssid = "mywifi";
const char *pw = "qwerty123";
IPAddress ip(192, 168, 0, 1);
IPAddress netmask(255, 255, 255, 0);
const int port = 9876;
int ledOn = 0;
int ledIntensity = 50;
WiFiServer server(port);
WiFiClient client;
char cmd[100]; // stores the command chars received from RoboRemo
int cmdIndex;
unsigned long lastCmdTime = 60000;
unsigned long aliveSentTime = 0;
boolean cmdStartsWith(const char *st) { // checks if cmd starts with st
for(int i=0; ; i++) {
if(st[i]==0) return true;
if(cmd[i]==0) return false;
if(cmd[i]!=st[i]) return false;;
}
return false;
}
// commands:
// l = ledOn
// s = stop
void exeCmd() { // executes the command from cmd
lastCmdTime = millis();
if( cmdStartsWith("l") ) {
analogWrite(ledOn, ledIntensity);
}
if( cmdStartsWith("s") ) {
analogWrite(ledOn, 0);
}
}
void setup() {
pinMode(ledOn, OUTPUT);
analogWrite(ledOn, 0);
delay(1000);
cmdIndex = 0;
WiFi.softAPConfig(ip, ip, netmask); // configure ip address for softAP
WiFi.softAP(ssid, pw); // configure ssid and password for softAP
server.begin(); // start TCP server
}
void loop() {
// if contact lost for more than half second
if(millis() - lastCmdTime > 500) {
// stop car:
analogWrite(ledOn, 0);
}
if(!client.connected()) {
client = server.available();
return;
}
// here we have a connected client
if(client.available()) {
char c = (char)client.read(); // read char from client (RoboRemo app)
if(c=='\n') { // if it is command ending
cmd[cmdIndex] = 0;
exeCmd(); // execute the command
cmdIndex = 0; // reset the cmdIndex
} else {
cmd[cmdIndex] = c; // add to the cmd buffer
if(cmdIndex<99) cmdIndex++;
}
}
if(millis() - aliveSentTime > 500) { // every 500ms
client.write("alive 1\n");
// send the alibe signal, so the "connected" LED in RoboRemo will stay ON
// (the LED must have the id set to "alive")
aliveSentTime = millis();
// if the connection is lost, the RoboRemo will not receive the alive signal anymore,
// and the LED will turn off (because it has the "on timeout" set to 700 (ms) )
}
}
Vicc- Posts : 7
Join date : 2016-06-07
Re: Add slider to control led intensity [ESP]
I figured out that these lines
- Code:
if( cmdStartsWith("ch") ) {
int ch = cmd[2] - '0';
if(ch>=0 && ch<=9 && cmd[3]==' ') {
chVal[ch] = (int)atof(cmd+4);
if(!servoCh[ch].attached()) {
servoCh[ch].attach(chPin[ch], usMin, usMax);
}
servoCh[ch].writeMicroseconds(chVal[ch]);
}
}
Vicc- Posts : 7
Join date : 2016-06-07
Re: Add slider to control led intensity [ESP]
Hi,
Here is that part of the code
Sorry for replying so late.
All the best,
Victor
Here is that part of the code
- Code:
int ledIntensity = 0;
void exeCmd() { // executes the command from cmd
if( cmdStartsWith("l") ) {
analogWrite(ledPin, ledIntensity);
}
if( cmdStartsWith("s") ) {
analogWrite(ledPin, 0);
}
if( cmdStartsWith("ch0 ") ) {
ledIntensity = (int)atof(cmd+4);
analogWrite(ledPin, ledIntensity);
}
}
Sorry for replying so late.
All the best,
Victor
Re: Add slider to control led intensity [ESP]
You may also get inspiration from this project:
http://www.roboremo.com/ac-lamp-dimmer.html
http://www.roboremo.com/ac-lamp-dimmer.html
Similar topics
» need to control smart servo with roboremo app slider
» Slider Speedometer
» 2 servo (bldc) with slider + 1 servo with accelerometer of mobile
» Fan speed control
» toggle - control
» Slider Speedometer
» 2 servo (bldc) with slider + 1 servo with accelerometer of mobile
» Fan speed control
» toggle - control
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|