Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19026
I don't think you connected the grounds, Dave.
|
 |
« Reply #30 on: May 22, 2010, 06:50:31 am » |
if (digit1 [glow]=[/glow] 1){ .... etc
THIS ISN'T CORRECT D a m n right  You need a "for" loop.
|
|
|
|
« Last Edit: May 22, 2010, 06:50:55 am by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #31 on: May 22, 2010, 07:25:58 am » |
Oh My God, I (totally noob) Got It!Full working code: const int pin = 0; // analog pin int digit1 = 0; int digit2 = 0; int tempc = 0; int LEDpin1 = 12; int LEDpin2 = 13; int LEDpin3 = 11; int var;
void setup() { Serial.begin(9600); // start serial communication pinMode(LEDpin1, OUTPUT); pinMode(LEDpin2, OUTPUT); pinMode(LEDpin3, OUTPUT); }
void loop() { for(int i = 0; i < 8; i++) { tempc += analogRead(pin); }
tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0);
digit1 = tempc / 10; // get the ten's digit digit2 = tempc % 10; // get the one's digit
var = 0; while(var < digit1){ digitalWrite(LEDpin1, HIGH); delay(500); digitalWrite(LEDpin1, LOW); delay(500); var++; }
digitalWrite(LEDpin2, HIGH); delay(500); digitalWrite(LEDpin2, LOW); delay(500); var = 0; while(var < digit2){ digitalWrite(LEDpin3, HIGH); delay(500); digitalWrite(LEDpin3, LOW); delay(500); var++; }
Serial.println(tempc,DEC);
delay(1400); // delay before loop }
I think that if the temperature is 22.9 degrees, it still gives me 22 degrees. Maybe someone knows how to round 22.9 to 23 degrees?I mean to round this value: tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0);
|
|
|
|
« Last Edit: May 22, 2010, 09:57:29 am by Fredx »
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 137
Posts: 19026
I don't think you connected the grounds, Dave.
|
 |
« Reply #32 on: May 22, 2010, 08:58:28 am » |
Maybe someone knows how to round 22.9 to 23 degrees? Same as always - add 0.5, and assign the result to an "int".
|
|
|
|
« Last Edit: May 22, 2010, 09:02:26 am by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #33 on: May 22, 2010, 09:53:54 am » |
tempc = (5.0 * tempc * 100.0) / (8.0 * 1024.0);
int tempb = tempc + 0.5; Does it do this: 22.1 + 0.5 = 22.6 -> ROUNDED to 2222.4 + 0.5 = 22.9 -> ROUNDED to 2222.6 + 0.5 = 23.1 -> ROUNDED to 23Isn't "tempc" already been rounded, because it's INT ? (plz look Reply #31)
|
|
|
|
« Last Edit: May 22, 2010, 10:12:56 am by Fredx »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35483
Seattle, WA USA
|
 |
« Reply #34 on: May 22, 2010, 11:05:19 am » |
Does it do this:
22.1 + 0.5 = 22.6 -> ROUNDED to 22 22.4 + 0.5 = 22.9 -> ROUNDED to 22 22.6 + 0.5 = 23.1 -> ROUNDED to 23 Yes. Except that the number is truncated, not rounded. Isn't "tempc" already been rounded, because it's INT ? No. When a floating point number is stored in an int, the decimal portion is truncated.
|
|
|
|
« Last Edit: May 22, 2010, 11:05:57 am by PaulS »
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #35 on: May 22, 2010, 12:59:04 pm » |
Thank you. Is it ok when i use temperature sensor WITHOUT a resistor?In datasheet it is written: 1) Operates from 4 to 30 Volts 2) Less than 60 µA current drain 3) Low impedance output, 0.1 ohm for 1mA load 4) Supply Voltage +35V to -0.2V 5) Output Voltage +6V to -1.0V 6) Output Current 10 mA 
|
|
|
|
« Last Edit: May 22, 2010, 01:06:57 pm by Fredx »
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #36 on: May 22, 2010, 01:16:09 pm » |
@ Ladyada.net -> It seems that I can use it without resistor.  I noticed that Duemilanove-s power consumption is quite noticeable - I connected new 9V battery to my project and after about 3 hours continuous use the voltage level has fallen from 9.5V to 7.7V So approximately 3-4 hours more and the minumum Operating Voltage is exceeded. Should conside to grab some rechargeable batteries.
|
|
|
|
« Last Edit: May 22, 2010, 03:06:08 pm by Fredx »
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #37 on: May 24, 2010, 04:29:53 am » |
Just for curiosity - is Arduino capable of blinking 2 leds at the same time? For example, when the temperature is 23 degrees, then both leds start to blink at the same time, one just does 1 blink extra? I know that the commands executed by arduino can't be run in parallel.. but maybe with a little shift. Maybe it is possible to add extra variable var = 0; while(var < digit1, var < digit2){ <- I know this is wrong but maybe some other statement will do? digitalWrite(LEDpin1, HIGH); and digitalWrite(LEDpin2, HIGH); delay(500); digitalWrite(LEDpin1, LOW); and digitalWrite(LEDpin2, LOW); delay(500); var++; }
|
|
|
|
« Last Edit: May 24, 2010, 04:57:14 am by Fredx »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35483
Seattle, WA USA
|
 |
« Reply #38 on: May 24, 2010, 04:58:20 am » |
while(var < digit1, var < digit2){ <- I know this is wrong but maybe some other statement will do?
while(var < digit1 && var < digit2) { digitalWrite(LEDpin1, HIGH); digitalWrite(LEDpin2, HIGH); delay(500);
digitalWrite(LEDpin1, LOW); digitalWrite(LEDpin2, LOW); delay(500); var++; } Both lights will blink at the same time (or close enough that you can't tell the difference), the same number of times.
|
|
|
|
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #39 on: May 24, 2010, 05:09:16 am » |
Thanks for fast reply  But what happens, if we have a situation like this? Do they both blink 2 times or 3 times? digit1 = 2; digit2 = 3;
while(var < digit1 && var < digit2) { digitalWrite(LEDpin1, HIGH); digitalWrite(LEDpin2, HIGH); delay(500);
digitalWrite(LEDpin1, LOW); digitalWrite(LEDpin2, LOW); delay(500); var++; }
Is it possible to make these leds blink different number of times? It sounds quite complicated.. it is 23 degrees: Led1__Led2 BLINK BLINK <- at the same time BLINK BLINK ______BLINK
|
|
|
|
« Last Edit: May 24, 2010, 05:24:07 am by Fredx »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35483
Seattle, WA USA
|
 |
« Reply #40 on: May 24, 2010, 07:02:52 am » |
With that while loop, they will blink twice. Try this: int val1 = 3; int val2 = 8; int val = 0; while(val < val1 || val < val2) { if(val < val1) digitalWrite(ledPin1, HIGH); if(val < val2) digitalWrite(ledPin2, HIGH);
delay(500);
digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW);
val++; }
|
|
|
|
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #41 on: May 24, 2010, 07:30:48 am » |
almost, except (for 23 degrees) they dont blink, but led2 stays a little longer ON than led1.
Let it be.. im working with another project.
Thank you for your help!
--------------------
The second project i'm planning, is to add two input buttons to arduino, so that when i press button no. 1 - then arduino starts to measure the temperature (for 3 times) and when i press button no. 2 - arduino starts to measure something else (maybe humidity... but i haven't got the sensor yet).
|
|
|
|
« Last Edit: May 24, 2010, 07:41:58 am by Fredx »
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35483
Seattle, WA USA
|
 |
« Reply #42 on: May 24, 2010, 07:40:00 am » |
Put the missing delay after turning the LEDs off back in, and it should work.
|
|
|
|
|
Logged
|
|
|
|
|
Europe, Estonia
Offline
Full Member
Karma: 0
Posts: 208
|
 |
« Reply #43 on: May 24, 2010, 07:52:17 am » |
leds light up with a little shift, but it's ok. Thanks again!
|
|
|
|
|
Logged
|
|
|
|
|
|