Remove these ads by
Signing UpStep 1: Get The Hardware Required
1-arduino
1-330ohm resistor
1-common cathode or common anode rgb led
1-breadboard
5-jumper wires
Remove these ads by
Signing Up
PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format.
You also have the ability to customize your PDF download.
Many thanks
Just think of a way to map the values from the pressure sensor on color.
Example > red is 0-100, green is 100-200, blue is 200-300.
That would be static switches, if you want more dynamic color smoothing then it will be a bit trickier, but absolutely doable.
sketch_oct19a.cpp: In function 'void loop()':
sketch_oct19a:42: error: expected `)' before 'if'
sketch_oct19a:43: error: expected `)' before 'if'
sketch_oct19a:44: error: expected `)' before 'analogWrite'
maewert, your code verifys these errors???
can you assist?
A quick review of the code seems to show there there are no 'break' statements between the 'case's. So once the random number picks one case all of the following case statements would be executed as well. Wouldn't this repeat the same random sequence (i.e. after the yellow is shown it is always followed by cyan, megenta, then white)?
(Also note that random(6) returns numbers from 0 to 5 but does not return 6 itself.)
This might still look nice but an even more colorful more random display may result if you drove each color using a PWM pin and for each you set to random(255) values like so:
////////////////////////////////////////////////////////////////////////////////////////////
int a = 1000; //this sets how long the LED stays one color for
int red = 11; //this sets the red led pin
int green = 10; //this sets the green led pin
int blue = 9; //this sets the blue led pin
void setup()
{ //this sets the output pins
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
}
void loop()
{
analogWrite(blue, random(255);
analogWrite(red, random(255);
analogWrite(green, random(255);
delay(a);
}
////////////////////////////////////////////////////////////////////////////////////////////
(I didn't compile this so it may be buggy)
Just a thought.
Best Wishes.
You can aso give this one a try. It slowly fades betweens random colors:
int red = 11; //this sets the red led pin
int green = 10; //this sets the green led pin
int blue = 9; //this sets the blue led pin
int redNow;
int blueNow;
int greenNow;
int redNew;
int blueNew;
int greenNew;
void setup()
{ //this sets the output pins
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
redNow = random(255);
blueNow = random(255);
greenNow = random(255);
redNew = redNow;
blueNew = blueNow;
greenNew = greenNow;
}
#define fade(x,y) if (x>y) x--; else if (x<y) x++;
void loop()
{
analogWrite(blue, blueNow);
analogWrite(red, redNow);
analogWrite(green, greenNow);
redNew = random(255);
blueNew = random(255);
greenNew = random(255);
// fade to new colors
while ((redNow != redNew) ||
(blueNow != blueNew) ||
(greenNow != greenNew))
{
fade(redNow,redNew)
fade(blueNow,blueNew)
fade(greenNow,greenNew)
analogWrite(blue, blueNow);
analogWrite(red, redNow);
analogWrite(green, greenNow);
delay(20);
}
}
I am very new to the Uno, and to programming for that matter!
Could I ask nicely how you could incorporate a flickering LED to Pin 8?
I don't know how to run two routines without causing one to stop :-(
I can read up on things but its a pity there are no local night classes for absolute beginners!
Often we can combine two sample programs by adding what each one has in the Setup and the loop. This only works if the two routines do not 'step on' each other, which I mean that each routine uses different pins and variables, etc.
I don't have any code that implements 'flickering' but I'll try to make something up :-). Two ways come to mind, we can use random numbers to set the brightness and the duration of the LED if we use Pulse Width Modulation like we did for setting the colors of the RGB LED. Second way would be to not use PWM but to simply use random numbers to set the duration of on and off for the LED. Pin 8 is one of the Arduino pins that does NOT support PWM. We'd have to use pin 5 or 6 if we wanted to use PWM. Lets try it with pin 8 and not use PWM.
Give this a shot:!
int red = 11; //this sets the red led pin
int green = 10; //this sets the green led pin
int blue = 9; //this sets the blue led pin
int flickerLED = 8; // flicker on pin 8
int redNow;
int blueNow;
int greenNow;
int redNew;
int blueNew;
int greenNew;
int flickertime;
void setup()
{ //this sets the output pins
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(flickerLED,OUTPUT);
redNow = random(255);
blueNow = random(255);
greenNow = random(255);
redNew = redNow;
blueNew = blueNow;
greenNew = greenNow;
}
#define fade(x,y) if (x>y) x--; else if (x
void loop()
{
analogWrite(blue, blueNow);
analogWrite(red, redNow);
analogWrite(green, greenNow);
redNew = random(255);
blueNew = random(255);
greenNew = random(255);
// fade to new colors
while ((redNow != redNew) ||
(blueNow != blueNew) ||
(greenNow != greenNew))
{
fade(redNow,redNew)
fade(blueNow,blueNew)
fade(greenNow,greenNew)
analogWrite(blue, blueNow);
analogWrite(red, redNow);
analogWrite(green, greenNow);
flickertime = random(20);
digitalWrite(flickerLED,HIGH);
delay(flickertime);
digitalWrite(flickerLED,LOW);
delay(20-flickertime);
}
}
When you copy text from the forum and paste it you don't seem to get what you think you were going to get!
So, I must appologise because it was not your code that had the fault it was me.
Thanks
No idea why this worked but it did :-)
I just chuffed off the following
redNew = redNow;
blueNew = blueNow;
greenNew = greenNow;
form the Void Loop as it was already in the Void Setup.
Now all I have to do is understand why it worked!
This is a whole new world :-0
And I have found the door, all I need to do now is go through the door and see how far down the rabbit hole goes.........................................................
This is where I come unstuck :-(
The code generates the following:
Maewert.cpp: In function 'void loop()':
Maewert:42: error: expected `)' before 'if'
Maewert:43: error: expected `)' before 'if'
Maewert:44: error: expected `)' before 'analogWrite'
Maewert:53: error: expected `}' at end of input
But I have no idea how to fix it.
Just so I can look things up on the net, what is this code exactly? C? C+? or is it specific like Python?
I honestly do apreciate your time trying to show me the way!
Thanks
http://www.instructables.com/id/RGB-Color-Controllable-High-Power-LED-Room-%2b-Spot-/step6/circuit-operation/
I have not worked with high power LEDs but I recently purchased 60 RGB LEDs and I have lots of superbright LEDs left over from other projects. I'm thinking about doing something like this as well only using a number of individual color LEDs. Maybe something that would shine behind my flat panel monitors on the rather stark white walls of my office would be nice. Six LEDs of each color would be 18 LEDs, each taking about 20mA will still be less than 1/2 amp, easily handled with three 2N2222A transistors. Could easily double the number of LEDs.
Might be nice to add a bit of color :-)