Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino Code #1

Open
rudmac opened this issue Apr 25, 2016 · 0 comments
Open

Arduino Code #1

rudmac opened this issue Apr 25, 2016 · 0 comments
Assignees

Comments

@rudmac
Copy link
Owner

rudmac commented Apr 25, 2016

/* 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);
}

@rudmac rudmac self-assigned this Apr 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant