maybe a simpel question

Mejlby

Member
hello All

Yes ... I am beginner but has since already found out a lot. is there anyone who will explain to me what "if b0> 200 then" means. what does 200? is the milliamp or voltage? (Normally I can see that it is used in connection with "readadc")

#picaxe 18m2

main:
touch C.0, b0
if b0 > 200 then
high B.4
else
low B.4
end if

touch C.1, b1
if b1 > 200 then
high B.5
else
low B.5
end if

touch C.2, b2
if b2 > 200 then
high B.6
else
low B.6
end if

touch B.3, b3
if b3 > 200 then
high B.7
else
low B.7
end if


'debug

goto main
Best Regards
Tonny ( From Denmark )
 

eclectic

Moderator
Tonny.
It looks like you have the
18M2 touch sensor board.

Try this program, and it might help you.

Code:
#picaxe 18m2

main:
touch C.0, b0

touch C.1, b1

touch C.2, b2

touch B.3, b3

sertxd(#b0," ",#b1, " ", #b2, #b3, cr,lf)
pause 1000
goto main
Then please see
Manual 2 page 231

Ec
 

BeanieBots

Moderator
if b0> 200 then
means if the variable called "b0" contains a value greater than 200 then.... go someplace else in the code.

What it means in relation to touch sensors (using my crystal ball to guess what you're doing) then the "200" is just an arbitary value who's size is a function of how big the "thing" close to the touch sensor is. The touch sensor works because when an object gets close, the CAPACITANCE of the plate gets higher. So, although there is no real scaling to that magical number, it is effectively a measure of capacitance.

Hope that helps.
 

Mejlby

Member
not really understand !!!!

Hello
Thanks for your reply - but I do not really understand what the variable - for example <200 means. I've made the following hours which works fine. As I understand, so does the command "readadc" read the voltage.

Depending on how much I screw the potentiometer up then I get a longer time period. I have 2 potentiometer - one for minute and one for second.

Or maybe it's something else happening with the command: "readadc"? Maybe you can explain what happens with the program I've created?

Many greetings
Tonny

Just a little bit of the program: ( I can´t send all )


main:

if pinC.6 = 1 then go ; sub to go if pin0 is high

goto main
go:

readadc C.0,b1 ; read value into b1

if b1 <= 1 then sekunder ; jump to sekunder0 if b1 <=1

if b1 <= 74 then minute1 ; jump to minute1 if b1 <=74

if b1 <= 149 then minute2 ; jump to minute2 if b1 <=149

if b1 <= 199 then minute3 ; jump to minute3 if b1 <=199

if b1 <= 249 then minute4 ; jump to minute4 if b1 <=249

if b1 >=251 then minute5 ; jump to minute5 if b1 <=251

sekunder:

readadc C.1,b2 ; read value into b1

if b2 <= 1 then sekund0
if b2 < 5 then sekund1
if b2 < 9 then sekund2
if b2 < 13 then sekund3
if b2 < 18 then sekund4
if b2 < 22 then sekund5
if b2 < 26 then sekund6
if b2 < 31 then sekund7
if b2 < 36 then sekund8
if b2 < 40 then sekund9
if b2 < 45 then sekund10
if b2 < 49 then sekund11
if b2 < 54 then sekund12
if b2 < 59 then sekund13
if b2 < 63 then sekund14
if b2 < 68 then sekund15
if b2 < 72 then sekund16


And little more !!!!

minute1:
high B.1 ; switch on output 1
wait 60 ; wait 1 minute
goto sekunder

minute2:
high B.1 ; switch on output 1
wait 60 ; wait 1 minute
wait 60 ; wait 2 minute
goto sekunder

minute3:
high B.1 ; switch on output 1
wait 60 ; wait 1 minute
wait 60 ; wait 2 minute
wait 60 ; wait 3 minute
goto sekunder

minute4:
high B.1 ; switch on output 1
wait 60 ; wait 1 minute
wait 60 ; wait 2 minute
wait 60 ; wait 3 minute
wait 60 ; wait 4 minute
goto sekunder

minute5:
high B.1 ; switch on output 1
wait 60 ; wait 1 minute
wait 60 ; wait 2 minute
wait 60 ; wait 3 minute
wait 60 ; wait 4 minute
wait 60 ; wait 5 minute
goto sekunder


And little more !!!


sekund0: ; switch off output 1
low B.1 ; switch off output 1
goto main ; loop back to start

sekund1:
wait 1 ; wait 1 seconds
low B.1 ; switch off output 1
goto main ; loop back to start

sekund2:
high B.1
wait 2 ; wait 2 seconds
low B.1 ; switch off output 1
goto main ; loop back to start


sekund3:
high B.1
wait 3 ; wait 3 seconds
low B.1 ; switch off output 1
goto main ; loop back to start

sekund4:
high B.1
wait 4 ; wait 4 seconds
low B.1 ; switch off output 1
goto main ; loop back to start

sekund5:
high B.1
wait 5 ; wait 5 seconds
low B.1 ; switch off output 1
goto main ; loop back to start

sekund6:
high B.1
wait 6 ; wait 6 seconds
low B.1 ; switch off output 1
goto main ; loop back to start

sekund7:
high B.1
wait 7 ; wait 7 seconds
low B.1 ; switch off output 1
goto main ; loop back to start

sekund8:
high B.1
wait 8 ; wait 8 seconds
low B.1 ; switch off output 1
goto main ; loop back to start

and so on !!!!!!!!
 
Last edited:

MartinM57

Moderator
A quick scan seems to suggest you are on the right lines with the readadc and variable checking. Well done!

However, your code is very very long - with a bit of thought it could be really really short ;)

Have a think about building up a variable as you read the potentiometers that indicates how many seconds you want to "wait" for - probably need to use a word variable if you want to wait for over 255 seconds, then..

Code:
' ....calculate wait time in seconds according to potentiometers, store in say w3
'
high B.1
for w4 = 1 to w3
    wait 1
next
low B.1
...much simpler :D
 

geoff07

Senior Member
I think you are making things a little too complicated. What I think you are doing is setting a time delay depending upon the setting read by readadc. I think you mean something like this:

main: do
if pin c.6 = 1 then gosub switchon
loop
end

switchon: readadc c.0, b1
'calculate w2=pause length in mS depending on b1 value
high B.1
pause w2
low B.1
return

The calculation depends on the value read into b1 and needs you to work out a suitable expression that applies in all cases. There is no need to list the entire set of possibilities. Do the calculation into w2 rather than b2 because that allows larger numbers (up to 65335 rather than 255). Pause works in milliseconds - if that is not long enough (max 65335 mS) there are other commands in the manual that give longer delays.

b0, b1, and w2 are all variables i.e. the names of numbers that can take different and changing values. b1 gets a value after you do the readadc instruction.

"if b1 < 200 then do something" means simply that if the value stored in b1 at that moment is less than 200 then do whatever comes next. This is how software can be used to make decisions and choose alternative actions.

Make the computer do the work, it doesn't need it all spelled out.
 

BeanieBots

Moderator
Mejlby, I think it would help us all if you explain what you are trying to do.
You start by asking about "touch" and now you ask about "ReadADC".
What is the objective of your project?
 

MartinM57

Moderator
I presume this the UV light box from one of Tonny's previous posts?

I think the touch red herring was just allowing a question about variables to be asked.

Maybe.
 
Top