Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define variables:
- /*
- byte ledG=5;
- byte ledR=3;
- byte ledB=6;
- */
- byte current[3]={255,255,255};
- void setup(){
- pinMode(3, OUTPUT);
- pinMode(5, OUTPUT);
- pinMode(6, OUTPUT);
- // Make random seed to generate colours:
- randomSeed(analogRead(0));
- }
- void loop(){
- // Assign values to each color
- byte newR=(byte) random() % 255;
- byte newG=(byte) random() % 255;
- byte newB=(byte) random() % 255;
- while(current[0] != newR || current[1] != newG || current[2] != newB){
- current[0]=adjust(current[0], newR, 3);
- current[1]=adjust(current[1], newG, 5);
- current[2]=adjust(current[2], newB, 6);
- }
- /* more efficient but
- /* while(current[0] != newR){ */
- /* current[0]=adjust(current[0], newR, 3); */
- /* } */
- /* while(current[1] != newG){ */
- /* current[1]=adjust(current[1], newG, 5); */
- /* } */
- /* while(current[2] != newB){ */
- /* current[2]=adjust(current[2], newB, 6); */
- /* } */
- delay(180000);
- }
- byte adjust(byte oldVal, byte newVal, byte pinNo){
- if(oldVal > newVal){
- analogWrite(pinNo, oldVal-1);
- return oldVal-1;
- }else if(oldVal < newVal){
- analogWrite(pinNo, oldVal+1);
- return oldVal+1;
- }else{
- return oldVal;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement