I use bluetooth and bluetooth electronics app on phone. When I press a button and then another in the application I have a loop in the last part of the code:
int gaisma;
float lights;
bool manual = 0;
int n;
char k;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
gaisma = 1023 - analogRead (A0);
//gaisma = map(gaisma, 0,1023,0,100);
lights = gaisma * 0.09775171;
Serial.println("*I"+String(lights)+"%*");
Serial.println(lights, 1);
if(Serial.available() > 0)
{k = Serial.read();}
if ( k == 'N')
{
manual = 1;
}
if ( k == 'K' )
{
manual = 0;
}
if (lights <= 30 && manual == 0 )
{Serial.print("*MR255G255B255*");}
if (lights <= 80, lights >= 41 && manual == 0)
{Serial.print("*MR150G150B150*");}
if (lights <= 100,lights >= 81 && manual == 0)
{Serial.print("*MR0G0B0*");}
if ( k == 'O' && manual == 1 )
{
n = Serial.parseInt();
Serial.print("*MR250G00B00*");
Serial.println(n);}
return;
}
In this part there is a constant cycle but sometimes it comes back as needed
if ( k == 'O' && manual == 1 )
{
n = Serial.parseInt();
Serial.print("*MR250G00B00*");
Serial.println(n);}
return;
P.S. Maybe there is a video with this program and how to program it. Thanks.