So, I'd like to use a visual interface in Processing to blink three LED's on and off without using "delay();". The point is to use a slider interface to change the period of time each LED spends on with a constant off time (~100ms). It's essentially a super slow PWM.
I'm mashing up this with the first code example here. The processing sketch I'm using for the interface is here. The only think I really need the interface for is handing a value between 0 and 255 to the incomingByte[i] array. Below is the code I've come up with so far:
- Code: Select all
const int ledPin[] = {5,6,3};
int ledState = LOW;
long previousMillis = 0;
long interval = 100;
int incomingByte[3];
void setup() {
Serial.begin(9600);
for (int i=0; i<3; i++) {
pinMode(ledPin[i], OUTPUT);
}
}
void loop()
{
unsigned long currentMillis = millis();
if (Serial.available() >= 3) {
for (int i=0; i<3; i++) {
incomingByte[i] = Serial.read();
if(currentMillis - previousMillis > incomingByte[i]) {
previousMillis = currentMillis;
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(ledPin[i], ledState);
}
}
}
}
The results are pretty erratic, with only one LED at a time doing the blink routine. When you drag the dots around the interface one LED will start blinking, turning the other one that was blinking off. Right now the on time and off time are both == incomingByte[i]. I'd like to get the "off" time set by a variable so I can play with it and adjust the on time with the interface.
Any advice?

