Temperature to flash a light part1

gengis

New Member
I have, in spite of my programming, managed to get a light to flash in sync with the temperature. A temperature of 71F flashes seven times, pauses then flashes once. But a temperature of 70F flashes just like 71. (the led is tricolor, common anode - so low is "on")

How does one get a for next loop to flash Zero times?

Dissecting the program, I tried
for b5= 0 to 0 flashes once
b5= 0 to 1 flashes twice
b5= 1 to 1 flashes once
b5= 1 to N flashes N

Code:
runn:
 for b5 = 0 to 1 low red
    pause 200
    high red
    pause 200
    next
    pause 1000
goto runn
 

Dippy

Moderator
Maybe you could try the do loop until type method.
Or, rather DO Until ... Loop perhaps.
Depending where you have your comparative test you can have a null loop.
I assume this works in PICAXE BASIC?

Remember , a FOR-NEXT loop will do the test after
 

hippy

Ex-Staff (retired)
FOR-NEXT loops always execute at least once on a PICAXE. There are a couple of choices; place the FOR-NEXT within an IF-ENDIF statement or use a DO-WHILE loop ...

Code:
If N <> 0 Then
  For var = 0 To N
    [i]whatever[/i]
  Next
End If
 

gengis

New Member
Thanks

The syntax check chokes on trying to nest for/next in if/then and tells me there's an endif with no if.

But this does seem to work although just in the dissection for now

Code:
runn:
b3 = 0      'arbitrary for testing

If b3 <=0 Then runn

  For b5 = 1 To b3 low red
    pause 200
    high red
    pause 200
    next
    pause 1000
    goto runn

pause 2000
goto runn
Just test b3. Zero in b3 gives zero flashes and N gives N flashes
 

Dippy

Moderator
Compare your method with my suggestion...

Code:
runn:
b3 = 0      'arbitrary for testing
b4 = b3 ' copy here for testing
If b3 <=0 Then runn
  For b5 = 1 To b3
    high  1
    pause 200
    low 1
    pause 200
  next
   pause 1000
 
'alternative method, no ifs or buts..
do until b4=0
   dec b4
   high 1
   pause 200
   low 1
   pause 200
loop
 
pause 2000
goto runn

... let that imagination flow.....
 

gengis

New Member
Dippy, your suggestion does work This is what I have:
Code:
high 0
runn:
b4=5  ' arbitrary set from 0 to N

do until b4=0
   dec b4
   low 1
   pause 200
   high 1
   pause 200
loop
 
pause 2000
goto runn
This seems obvious (now). I neglected to set output 0 (my red led, to high -"off") What was happening was the red led was coming on because after the program loads pin 7 (physical) is low turning on the led. The blue led was on physical pin 6 (out 1). Since it takes 3+ volts to light blue and only ~2 volts to light red the red was lighting and working as a zener to keep the voltage drop across the resistor to the common anode too high to light the blue, as long as red was lit.

This would have been instantly obvious if I had a small resistor on the red led so it couldn't hog all the current.

Armed with that knowledge, I have to go back and retry what hippy was telling me
 

william47316

New Member
i would have gone like this

Code:
... snip
b1 = degfarn / 10
for b3 = 0 to b1
pulsout redpin, 500
next
pause 1000
b1 = degfarn // 10
for b3 = 0 to b1
pulsout greenpin, 500
next
... snip
or is there something im missing
 

Dippy

Moderator
Like many things in life, there are plenty of ways to achieve the same goal.
Do what you are happy with and that is reasonable space/speed efficient.

The important thing , at this stage, is that you understand it.

William, what happens in your example if we have a zero?
How many flashes?
 

Dippy

Moderator
Maybe you/we would, but the question in Post#1 was:
"How does one get a for next loop to flash Zero times?"

I assumed that if Flooby was happy with a one flash for zero and one then he wouldn't have posted the question.
I probably misunderstood.
Maybe something else could represent zero to remove ambiguity...?
 

gengis

New Member
I thought I'd go with no flash for zero. Timing is good enough to remove ambiguity.

A wireless thermometer . . .
 

hippy

Ex-Staff (retired)
The ambiguity is that if the LED isn't flashing, is the temperature zero or is the wireless not passing any data, and what if the temperature is below 11 or over 99... is one flash 1, 10 or 100 ?
 

marks

Senior Member
Wireless i,d really like to see the finished project!

really good questions from Hippy that need cosidering.

if sending raw data from the ds18b20 and converting to fahrenheit
zero data would actually display 32 but you could code with a special flash or colour
you could make 32 red /blue increase the colours (red+blue =purple lol)
you could increase the the resolution ie 32.1 so zero point occurs less often

the bit of code i placed in part 2 will do from 2- 257 F
the timing for 1 or 10 or 100 needs too be different
units really fast (1 wouldnt worry temp to low)
tens fast (10 would be blue)
hundreds slow so you would be able to tell the difference(100 would be red colour)
i think 11 22 33 etc ok as you see the different pulse rates.
ideas lol
 
Last edited:

gengis

New Member
The ambiguity is that if the LED isn't flashing, is the temperature zero or is the wireless not passing any data, and what if the temperature is below 11 or over 99... is one flash 1, 10 or 100 ?
In my neck of the woods, I never expect to see Zero degrees F There's be no mistaking 100 for 0 - different seasons, frost or sweltering heat. Ten and one degrees, or twenty and two, might be a problem - but we haven't seen temperatures like that in the last 20 years or so (20 possible, but unlikely, 10 very unlikely, 1 or 2 probably not in this lifetime).

I suppose I could do something hinky with the colors and flashing to indicate a demarcation between tens/units etc. I'll try it without, if that doesn't work it is re programmable.

The "wireless" was intended facetiously. Light is electromagnetic radiation just like radio waves, and there are no wires between the source and detector...

Realistically, it shouldn't be too difficult to come up with simple protocol for an axe at the receiving end to interpret - or to use one of the built in widgets like IR or servo commands to modulate the transmitter. But I just intended it for flashing colored lights.
 

gengis

New Member
This way insanity lies - but it would be a piece of cake to to use "servo" and just put an actual servo to indicate the temp with a big dial thermometer remotely...
 
Top