hello all!
I'm working on a project called star field project
What do I have
arduino uno
bright green, blue and white LED light, each with a resistor of 180ohm
a 16x2 LCD with backpack from Adafruit
and finally, fiberglass...
I have made a code, so that the LEDs fade random soft, sometimes hard that totalle working and awesome.
My first problem was that the outputs same steps had. exmp. green, blue, white, green, blue, white, ... and go on.
void loop() {
schermpje(); //lcd screen
bluelight(); // blue
witlight(); //white
groenlight(); //green
}
So I called help on you, and change that stiff to :
int pick( int a, int b)
{
return random(2) ? a : b ;
}
void loop() {
static int next;
schermpje();
switch (next) {
case 0: witlight(); next= pick( 1,2); break;
case 1: bluelight(); next= pick( 0,2); break;
case 2: groenlight(); next= pick( 0,1); break;
}
Thats cool and ok, but not realistic, the led's is still waiting on the othere led's
I like as the white LED is busy in hes fading, then the other mag also begin to fade, really random faden and not wait until the other has finished fading.
but would this mean that I have to go change my code or just in my loop? and how do I accomplish this?
this is the whole code :
#include <Wire.h>
#include <LiquidTWI.h>
LiquidTWI lcd(0); // Connect via i2c, standaard adres #0 (A0-A2 not jumpered)
int ledPin = 9; //Selecteren van pin
int witledPin = 10; //Selecteren van pin 10
int groenled = 11; //Selecteren van pin 11
int bl_rand_nr ; // getal waarde helder blauw
int wit_rand_nr ; // getal waarde helder wit
int gr_rand_nr ; // getal waarde helder groen
int gr_rand_nr2;
; // getal waarde helder groen
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);// set up the LCD's number of rows and columns:
}
void bluelight(){
bl_rand_nr = random(0, 255);
for(int fadeValue = 200 ; fadeValue <= 255; fadeValue +=5) {
analogWrite(ledPin, fadeValue);
delay(10); }
for(int fadeValue = 255 ; fadeValue >= (bl_rand_nr); fadeValue -=20) {
analogWrite(ledPin, fadeValue);
delay(100); }
}
void witlight(){
wit_rand_nr = random(0, 255);
for(int witfadeValue = 200 ; witfadeValue <= 255; witfadeValue +=5) {
analogWrite(witledPin, witfadeValue);
delay(10); }
for(int witfadeValue = 255 ; witfadeValue >= (wit_rand_nr); witfadeValue -=20) {
analogWrite(witledPin, witfadeValue);
delay(100); }
}
void groenlight(){
gr_rand_nr = random(0, 255);
gr_rand_nr2 = random(50, 150);
for(int groen = (gr_rand_nr2) ; groen <= 210; groen +=5) {
analogWrite(groenled, groen);
delay(10); }
for(int groen = 255 ; groen >= (gr_rand_nr); groen -=20) {
analogWrite(groenled, groen);
delay(100); }
}
void schermpje(){
lcd.clear(); //Eerst opkuisen
lcd.setCursor(0, 0); //plaatsen van cursor
lcd.print("HB:"); //geen BH maar HB van HelderBlauw
lcd.setCursor(4,0); //plaatsen van cursor voor de getallen
lcd.print(bl_rand_nr); //en print het getal maar!
lcd.setCursor(0, 1);
lcd.print("HW:");
lcd.setCursor(4,1);
lcd.print(wit_rand_nr);
lcd.setCursor(9, 0);
lcd.print("HGR:");
lcd.setCursor(13,0);
lcd.print(gr_rand_nr);
}
int pick( int a, int b)
{
return random(2) ? a : b ;
}
void loop() {
static int next;
schermpje();
switch (next) {
case 0: witlight(); next= pick( 1,2); break;
case 1: bluelight(); next= pick( 0,2); break;
case 2: groenlight(); next= pick( 0,1); break;
}
}