added dedicated normalized plotting function
This commit is contained in:
parent
65cde60d3f
commit
77785f4e43
@ -33,9 +33,8 @@ void compose() {
|
|||||||
case INCREASE:
|
case INCREASE:
|
||||||
brightness = increase_brightness(brightness, 1);
|
brightness = increase_brightness(brightness, 1);
|
||||||
|
|
||||||
Serial.print("INCREASING ");
|
plot("INCREASING", brightness);
|
||||||
Serial.println(brightness);
|
|
||||||
|
|
||||||
if (brightness > 250){
|
if (brightness > 250){
|
||||||
ledState = WAVE;
|
ledState = WAVE;
|
||||||
}
|
}
|
||||||
@ -43,36 +42,30 @@ void compose() {
|
|||||||
|
|
||||||
case DECREASE:
|
case DECREASE:
|
||||||
brightness = decrease_brightness(brightness, 0.5);
|
brightness = decrease_brightness(brightness, 0.5);
|
||||||
|
plot("DECREASING", brightness);
|
||||||
Serial.print("DECREASING ");
|
|
||||||
Serial.println(brightness);
|
|
||||||
if (brightness == 0){
|
if (brightness == 0){
|
||||||
ledState = OFF;
|
ledState = OFF;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WAVE:
|
case WAVE:
|
||||||
Serial.print("WAVE ");
|
plot("WAVE", brightness);
|
||||||
Serial.println(brightness);
|
|
||||||
doForMs(5000, wavyshine); // this you might want to do for number of pulses, rather than for duration
|
doForMs(5000, wavyshine); // this you might want to do for number of pulses, rather than for duration
|
||||||
ledState = DECREASE;
|
ledState = DECREASE;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STAY:
|
case STAY:
|
||||||
Serial.print("STAY" );
|
plot("STAY", brightness);
|
||||||
Serial.println(brightness);
|
|
||||||
brightness = brightness;
|
brightness = brightness;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ON:
|
case ON:
|
||||||
Serial.print("ON" );
|
plot("ON", brightness);
|
||||||
Serial.println(brightness);
|
|
||||||
brightness = 255;
|
brightness = 255;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OFF:
|
case OFF:
|
||||||
Serial.print("OFF" );
|
plot("OFF", brightness);
|
||||||
Serial.println(brightness);
|
|
||||||
brightness = 0;
|
brightness = 0;
|
||||||
doAfterMs(5000, goBackOn);
|
doAfterMs(5000, goBackOn);
|
||||||
break;
|
break;
|
||||||
@ -86,12 +79,20 @@ void goBackOn(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wavyshine(){
|
void wavyshine(){
|
||||||
Serial.print("WAVE ");
|
plot("WAVE", brightness);
|
||||||
Serial.println(brightness);
|
|
||||||
brightness = sinewave(1000,256,0); // you can tweak the parameters of the sinewave
|
brightness = sinewave(1000,256,0); // you can tweak the parameters of the sinewave
|
||||||
analogWrite(ledPin, brightness);
|
analogWrite(ledPin, brightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void plot(char *state, int brightness){
|
||||||
|
// use this function to plot a graph.
|
||||||
|
// it will normalize the auto-scaling plotter
|
||||||
|
Serial.print(state);
|
||||||
|
Serial.print(", ");
|
||||||
|
Serial.print(brightness);
|
||||||
|
Serial.println(", 0, 300");
|
||||||
|
}
|
||||||
|
|
||||||
int increase_brightness (int brightness, float velocity){
|
int increase_brightness (int brightness, float velocity){
|
||||||
return brightness = brightness + 1 * velocity;
|
return brightness = brightness + 1 * velocity;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user