You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Output
int redPin = 2; // Red LED, connected to digital pin 2
int grnPin = 3; // Green LED, connected to digital pin 4
int bluPin = 4; // Blue LED, connected to digital pin 3
String message = "";
int r = 255, g = 255, b = 255;
boolean stroble,use,on = false;
long strobleDelay = 0;
long previousMillis = 0;
void setup()
{
/* Set the baud rate for the hardware serial port */
Serial1.begin(9600);
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
}
/* Main loop that will pass any data to and from the Bluetooth mode to the
host PC */
void loop()
{
if (!use) {
while (Serial1.available() > 0) {
char inByte = Serial1.read();
if (inByte == FIM) {
//Serial1.flush();
use = true;
break;
}
else {
message += inByte;
}
}
}
/* Include the software serial port library */
include <SoftwareSerial.h>
//SoftwareSerial mySerial(19, 18); // RX, TX
define FIM '>'
// Output
int redPin = 2; // Red LED, connected to digital pin 2
int grnPin = 3; // Green LED, connected to digital pin 4
int bluPin = 4; // Blue LED, connected to digital pin 3
String message = "";
int r = 255, g = 255, b = 255;
boolean stroble,use,on = false;
long strobleDelay = 0;
long previousMillis = 0;
void setup()
{
/* Set the baud rate for the hardware serial port */
Serial1.begin(9600);
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(grnPin, OUTPUT);
pinMode(bluPin, OUTPUT);
}
/* Main loop that will pass any data to and from the Bluetooth mode to the
host PC */
void loop()
{
if (!use) {
while (Serial1.available() > 0) {
char inByte = Serial1.read();
if (inByte == FIM) {
//Serial1.flush();
use = true;
break;
}
else {
message += inByte;
}
}
}
if (use) {
char msg[20];
message.toCharArray(msg, sizeof(msg));
message = "";
sscanf(msg, "%i,%i,%i,%d,%i", &r, &g, &b, &stroble, &strobleDelay);
use = false;
}
if (stroble) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > strobleDelay) {
previousMillis = currentMillis;
if (on)
rgbOff();
else
rgbOn();
}
} else {
rgbOn();
}
}
void rgbOff() {
on = false;
analogWrite(redPin, 255);
analogWrite(grnPin, 255);
analogWrite(bluPin, 255);
}
void rgbOn() {
on = true;
analogWrite(redPin, r);
analogWrite(grnPin, g);
analogWrite(bluPin, b);
}
The text was updated successfully, but these errors were encountered: