salve a tutti, sto creando lo sketch per una lampada rgb, al momento ho questo sketch:
// fade + white button for rgb lamp
int button = 8;
int ledr = 9; // the pin that the LED is attached to
int ledg = 10;
int ledb = 11;int brightnessr = 10; // how bright the LED is
int brightnessg = 125;
int brightnessb = 250;int val = 0; // per il bottone
int old_val = 0; // for debouncing system
int state = 0; // for debouncyng systemint fadeAmountr = 1; // how many points to fade the LED by
int fadeAmountg = 2;
int fadeAmountb = 3;
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(ledr, OUTPUT);
pinMode(ledg, OUTPUT);
pinMode(ledb, OUTPUT);pinMode(button, INPUT);
}void loop() {
val = digitalRead(button); // debouncing system
if ((val == HIGH) && (old_val == LOW)){
state = 1 - state;
}old_val = val;
if (state == 1){ //stop debouncing system
analogWrite(ledr, 250);
analogWrite(ledg, 250);
analogWrite(ledb, 250);
}else{
analogWrite(ledr, brightnessr); // set the brightness
analogWrite(ledg, brightnessg);
analogWrite(ledb, brightnessb);brightnessr = brightnessr + fadeAmountr; // change the brightness for next time through the loop:
brightnessg = brightnessg + fadeAmountg;
brightnessb = brightnessb + fadeAmountb;// reverse the direction of the fading at the ends of the fade:
if (brightnessr <= 10 || brightnessr >= 250)
fadeAmountr = -fadeAmountr ;
if (brightnessg <= 10 || brightnessg >= 250)
fadeAmountg = -fadeAmountg ;
if (brightnessb <= 10 || brightnessb >= 250)
fadeAmountb = -fadeAmountb ;// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
tralasciando il casino o le note poco ordinate, stavo pensando che così non otterrò mai (quasi) tutti i colori in modo ciclico, ma anche semplicemente i colori di base non lì otterrò mai. come potrei fare a ottenerli (quasi) tutti in modo ciclico?