Show Posts
|
|
Pages: [1] 2 3 ... 9
|
|
1
|
Forum 2005-2010 (read only) / Troubleshooting / Re: Help Loop exit
|
on: September 11, 2009, 03:33:41 pm
|
|
Please, do not sorry, you are helping me!!
Thank you very much zed0,
Now my program is working, I changed the checkCommand by the Serial.available(), I have no problem sending again the 7 and restarted the fade function.
Thank you very much again.
|
|
|
|
|
2
|
Forum 2005-2010 (read only) / Troubleshooting / Re: Help Loop exit
|
on: September 09, 2009, 02:33:47 pm
|
Thank you Zed0, It is "almost working" ( much better that my, of course) Now I can exit the loop, but to exit the loop I need to send two commands (even if I wait for 10 seconds to send the first command) Do you know what could be the problem? 2 <<I sent 2 and it goes to red rgb value: 2 7 <<I sent 7 and it goes to fade rgb value: 7 2 <<I sent 2 and nothing change rgb value: 2 2 <<I sent 2 again and it goes to red rgb value: 2 7 rgb value: 7 <<and the something here again 2 rgb value: 2 2 rgb value: 2
|
|
|
|
|
3
|
Forum 2005-2010 (read only) / Troubleshooting / Re: Help Loop exit
|
on: September 08, 2009, 07:19:01 pm
|
|
Thank you AWOL, and excuse me about not using the # button when posting the code, that was my first time posting a code here.
As you can see, the checkCommand is used to see if I sent a serial command to change the color of my rgb led or I fade the rgb led.
Is there any way to solve the problem? How can I exit the loop as soon as I send the serial command?
|
|
|
|
|
4
|
Forum 2005-2010 (read only) / Troubleshooting / Help Loop exit
|
on: September 08, 2009, 02:26:45 pm
|
|
Hello all,
I´m doing a very simple program to control a RGB with serial.read.
For now when I send 1 I turn on RGB >Red, sending 2 RGB >green, sendind 3 RGB >blue and finally sending 7 the RGB start a loop to mix all colors. (and the mix works fine)
My problem starts when I try to exit the loop, for example, to turn on again the red RGB. I cannot exit the loop, the program remains in the fade routine. What I´m doing wrong?
Please, I need help to know how to exit the loop.
Thank you,
// programa para piscina
int redPin = 11; int greenPin = 10; int bluePin = 9;
//variaveis int red = 0; int green = 0; int blue = 0; int wait = 3000; int WAIT = 100; int rgb = 0;
//setup inicial
void setup() { pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); Serial.begin(9600);
//led inicial analogWrite(redPin, 16); analogWrite(greenPin, 16); analogWrite(bluePin, 16); }
void loop(){ checkCommand(); // verifica se chegou algo }
void checkCommand () { // programa para gerar as cores conforme data recebido if (Serial.available()) { rgb = Serial.read() - 48; Serial.println(rgb); Serial.print("rgb value: "); //for debug Serial.println(rgb); if (rgb == 1) { r(); } else if (rgb == 2) { g(); } else if (rgb == 3) { b(); }else if (rgb == 7) { fade(); } } } // rotinas void r(){ //cor vermelha solida color(255,0,0) ; } void g(){ //cor verde solida color(0,255,0) ; } void b(){ //cor azul solida color(0,0,255) ; } void fade() { //<<<<<< here start my problem to exit this loop while (rgb == 7){ checkCommand(); //I can see that the rgb value changes ( when I send 3, for example, it goes to 3) but has no effect in the while loop for (float f = 0; f < 1; f += 0.0005) {
hsv(f, 1, 1); delay(WAIT); } } } //} void hsv(float H, float S, float V) {
int var_i; float R, G, B, var_1, var_2, var_3, var_h;
if (S == 0) { R = V; G = V; B = V; } else { var_h = H * 6; if (var_h == 6) var_h = 0; var_i = int(var_h) ; var_1 = V * (1 - S ); var_2 = V * (1 - S * (var_h - var_i)); var_3 = V * (1 - S * (1 - (var_h - var_i)));
if (var_i == 0) { R = V; G = var_3; B = var_1; } else if (var_i == 1) { R = var_2; G = V; B = var_1; } else if (var_i == 2) { R = var_1; G = V; B = var_3; } else if (var_i == 3) { R = var_1; G = var_2; B = V; } else if (var_i == 4) { R = var_3; G = var_1; B = V; } else { R = V; G = var_1; B = var_2; } color(255 * R, 255 * G, 255 * B); } } void color(int red,int green, int blue) {
analogWrite(redPin, red); // Escreve o valor do PWM do led vermelho analogWrite(greenPin, green); // Escreve o valor do PWM do led verde analogWrite(bluePin, blue); // Escreve o valor do PWM do led azul
}
|
|
|
|
|
5
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Exponent of E
|
on: February 24, 2010, 02:41:38 pm
|
Hi Fletcher, Take a look here to give an idea how is the curve and the values: (My curve is not so linear, but my curve is similar to that) http://www.lakeshore.com/temp/sen/sd400_ts.html#curve10In my case I have almost 70 datapoints, that I received for the guy that I´m trying to make a display, instead using a voltmeter to view the temp. He has a machine that uses nitrogen to cold some wires, (I do not know exactly what the machine does) he uses something called coldhead to maintain the nitrogen temperature, and I know the preassure inside the (Closed) tank is about 10 PSI Jose
|
|
|
|
|
6
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Exponent of E
|
on: February 20, 2010, 12:43:29 pm
|
|
Hi Fletcher,
I´m measuring the temperature (nitrogen K degrees) with a diode, and I needed to divide the curve in two parts in order to work, one 3´th order the other 5´th order.
You´re right, I tried 7´th, 8 ´th and 9th orders and the best fit was the 6´th below 6 is not so good.
I also tried to fit the curve with excel but Origin did a best work.
Cristal
|
|
|
|
|
7
|
Forum 2005-2010 (read only) / Syntax & Programs / Re: Exponent of E
|
on: February 19, 2010, 12:43:45 pm
|
|
Thank you guys for the answers, but my doubt was exactly that, if the value of E = 2,71828183 or if the value is -0.00002.
I'm using a program called Origin to find the equation of a curve and the result came as y = -2E-05*x6 + 0.001*x5 - 0.036*x4 + 0.410*x3 - 2.215*x2 + 3.715*x + 20.01
Now I know that the value is really -0.00002.
Thank you again.
|
|
|
|
|