Go Down

Topic: Project 04 (Read 27578 times) previous topic - next topic

Gorduino283

I had an issue with LED not emitting one color while doing this project.  I realized the wire portions of two resistors were touching, causing cross talk.  Check the physical components!

RdeJong

Hello,

I was just playing around after finishing this project and see if I was able to make some random color mixing.
It took me some time to google, re-calculate and some trials and errors but i guess it is working fine now.
Just curious what you think about it.
Probably there is still room for improvement.

Regards,
Ruud


Code: [Select]
/*Begining of Auto generated code by Atmel studio */
#include <Arduino.h>
const int start_stop_button = 5;
unsigned long millis();
//unsigned long previous_time = 0;
int red = 0;
int green = 0;
int blue = 0;
int start_stop_button_status = 0;
int start_stop_button_previousscan = 0;
int period_time = 0;
boolean start = false;
float redfact = 0;
float greenfact = 0;
float bluefact = 0;
float radsec =(57.29577951*2.777777778);// 360/(2*pi)*(1000/360) from millisec to sec and degrees to radians

void setup() {
// put your setup code here, to run once:
pinMode(start_stop_button,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:

int start_stop_button_status = digitalRead(start_stop_button);
int brightness = analogRead(A0)/4;
int period_time=1+analogRead(A5)/17; //from 1 to 61 sec per sinus wave for red

if(start_stop_button_status != start_stop_button_previousscan)
if (start_stop_button_status == HIGH)
{start = !start ; }//previous_time = millis();}
if(start==true){
//previous_time=100+previous_time;
redfact=float ((1+sin((millis())/(radsec*period_time)))/2); //scaling from -1/1 sinus to 0/1
greenfact=float ((1+sin((millis())/(radsec*period_time*1.1)))/2);  //create some offset for green and blue
bluefact=float ((1+sin((millis())/(radsec*period_time*0.85)))/2);
// red=random(0,brightness);green=random(0,brightness);blue=random(0,brightness);}
red=redfact*brightness; red=constrain(red,0,255);
green=greenfact*brightness; green=constrain(green,0,255);
blue=bluefact*brightness; blue=constrain(blue,0,255); }
if(start==false){red=0;green=0;blue=0;}

analogWrite(9,red);analogWrite(10,green);analogWrite(11,blue);
{start_stop_button_previousscan=start_stop_button_status;}

if(start==true){
Serial.print("millis = ");
Serial.print(millis());
Serial.print(" brightness % = ");
Serial.print(float(analogRead(A0)/10.23));
Serial.print(" ");
/* Serial.print(millis())-previous_time);
Serial.print(" ");
*/ Serial.print(" period_time = ");
Serial.print(period_time);
Serial.print(" ");
Serial.print(redfact);
Serial.print(" ");
Serial.print(greenfact);
Serial.print(" ");
Serial.print(bluefact);
Serial.print(" ");
Serial.print(" red = ");
Serial.print(red);
Serial.print(" green = ");
Serial.print(green);
Serial.print(" blue = ");
Serial.print(blue);
Serial.println();}
//delay(pow(period_time,2));
}



jphys

Thank you kwok_leong1985.  Your code was very helpful!  I had similar issues with project 03 where I had to reset the LED's so that the temp wouldn't go our of whack. Somehow not everyone seems to have this issue.  Why? Could it be static in the winter or does my board have a ground loop?

Go Up