Touch problem 08m2

Hansen

Member
I can not find solution on this problem

I've tried to describe the function of the 2 touch buttons

2touch4func.jpg

my slave task "start2" look at the b1 to see if it change compare to b0

I need some advice Plz
 

erco

Senior Member
Post your code.

I'm brand new to the PicAxe, but my first attempt using the touch sensors on the 18M2 was successful. They work great.
 

nick12ab

Senior Member
Code:
 tags please[/b]

Please use [PLAIN][code]
[/PLAIN] tags around code instead of uploading it, then no one has to download it to see it. EXCEPTION - if code is far too much to fit in one post.

You should also include the #picaxe directive, which I've added.
Code:
' Base on  08M2  running in 2 task
' This is the controller & driver part 
' for the light control

        Symbol OnOff = C.0

        Symbol ALight = b0 ' actuel light level
        Symbol State = b1 
        
        
        let ALight = 0 ' value 0 to 4
        let State = 0 ' Value 0 to 4
        
        #picaxe 08M2    'This should be required by international law

start:

do
    Gosub Clearall
    ' look for touch less 1 sec on/off
    touch C.1,b7
    touch C.4,b8
    if b7> 100 then 
        b3 = 1  ' on
        endif
    if b8> 100 then 
        b4 = 1  ' off
        endif
    pause 900
    'look if still pressed
    touch C.1,b7
    touch C.4,b8
    if b7> 100 then 
        b5=1 'more light
        endif
    if b8> 100 then 
        b6=1 'less light
        endif
    ' Check for fake combo off touch
    if b3=1 and b4=1 then 
        gosub Clearall
        endif
    if b5=1 and b6=1 then 
        gosub Clearall
    if b3=1 and b6=1 then 
        gosub Clearall
    if b5=1 and b4=1 then 
        gosub Clearall
    ' Check for good combo
        ' on function
        
        
    ' next 4 If give me problem :(    
        
    if b3 = 1 and b5 = 0 and OnOff =0 then 
          c.0 =1
        endif
        ' more light function
    if b3 = 1 and b5 = 1 and c.0= 1 then 
        State =  State +1
        endif    
        ' Off functiln
    if b4 = 1 and b6 = 0 and c.0= 1 then
        c.0 = 0
        endif
        ' Less light
    if b4 = 1 and b6 = 1 and c.0= 1 then
        State = State -1
loop        
        
start2:     '

LightLoop:    
        if State > 4 then State = 4
        if State < 0 then State = 0
        if ALight<>State then LightOnOff
        wait 1
        goto LightLoop

LightOnOff:    
        let ALight=State
        If  ALight=0 Then goto LightOff
        If  Onoff >= 0 then goto Pwm_set
        Wait 1
        goto LightLoop
        
LightOff:    ' turn off light driver source & turn off PWM
        OnOff = 0
        let C.2 = 0
        wait 1
        goto LightLoop

LightOn:
        If OnOff = 0 then let OnOff = 1
Pwm_set:
        ' 4 step Pwm til Light driver
        If ALight =1 pwmout 2, 99, 16
        If ALight =2 pwmout 2, 99, 28
        If ALight =3 pwmout 2, 99, 40
        If ALight =4 pwmout 2, 99, 60
        goto LightLoop
        


Clearall: ' reset touch var
    b3=0
    b4=0
    b5=0
    b6=0
Return
 

Technical

Technical Support
Staff member
symbol onoff = pinC.0 (not C.0)

for lines such as

if b3 = 1 and b5 = 1 and pinc.0= 1 then

Also you accidentally have 3 tasks runing, task0 and task 1 are doing the same in parallel, task2 is different.
Use task 0 and 1, not 1 and 2, basically you don't need the start1: label where it is, as task0 starts automatically, and change start2: later on to start1:
 
Last edited:

Hansen

Member
symbol onoff = pinC.0 (not C.0)

for lines such as

if b3 = 1 and b5 = 1 and pinc.0= 1 then

Also you accidentally have 3 tasks runing, task0 and task 1 are doing the same in parallel, task2 is different.
Use task 0 and 1, not 1 and 2, basically you don't need the start1: label where it is, as task0 starts automatically, and change start2: later on to start1:
Thx for advice

code change

both stil some syntax problem :(

Code:
' Base on  08M2  running in 2 task
' This is the controller & driver part 
' for the light control

' b3 hold the touch function
' b3 = 1  for on
' b3 = 2  for off
' b3 = 17 for More light
' b3 = 34 for less light

		Symbol onoff = pinC.0
		Symbol ALight = b0 ' actuel light level
		Symbol State = b1 
		
		
		let ALight = 0 ' value 0 to 4
		let State = 0 ' Value 0 to 4

		#picaxe 08M2    
start:

do
	b3 = 0
	onoff = C.0
	' look for touch less 1 sec on/off
	touch C.1,b7
	touch C.4,b8
	if b7> 100 then 
		b3 = b3 or 1  ' on   (bit 1)
		endif
	if b8> 100 then 
		b3 = b3 or 2  ' off ( bit 2)
		endif
	pause 900
	'look if still pressed
	touch C.1,b7
	touch C.4,b8
	if b7> 100 then 
		b3= b3 or 16 'more light ( bit 5 )
		endif
	if b8> 100 then 
		b6= b6 or 32 'less light ( bit 6 )
		endif
	' on	
	if b3 = 1 and pinC.0 = 0 then 
		  pinC.0 =1
		endif
	' more light function
	if b3 = 17 and pinC.0= 1 then 
		State =  State +1
		endif	
	' Off functiln
	if b3 = 2 and pinC.0= 1 then
		pinC.0 = 0
		endif
		' Less light
	if b3 = 34 and pinC.0= 1 then
		State = State -1
	endif
loop		
		
start1:     '
		State = 0
do		
		if State > 4 then
			State = 4
		endif
		if State < 0 then 
			State = 0
		endif
		if ALight<>State then 
			Gosub LightOnOff
		endif
		wait 1
loop

LightOnOff:	
		let ALight=State
		If  ALight=0 Then goto LightOff
		If  Onoff >= 0 then goto Pwm_set
		Wait 1
		Return
		
LightOff:	' turn off light driver source & turn off PWM
		OnOff = 0
		let pinC.2 = 0
		wait 1
		Return

LightOn:
		If OnOff = 0 then 
			let OnOff = 1
		endif
Pwm_set:
		' 4 step Pwm til Light driver
		If ALight =1 then 
			pwmout 2, 99, 16
		endif
		If ALight =2 then 
			pwmout 2, 99, 28
		endif
		If ALight =3 then 
			pwmout 2, 99, 40
		endif
		If ALight =4 then 
			pwmout 2, 99, 60
		endif
		Return
 
Last edited:

nick12ab

Senior Member
Code:
if b1 > 4 then b1 = 0
You can only use (goto) label after an IF without ENDIF. Use
Code:
if b1 > 4 then : b1 = 4 : end if
and repeat a similar scheme for any that remain.
 

Hansen

Member
Code:
if b1 > 4 then b1 = 0
You can only use (goto) label after an IF without ENDIF. Use
Code:
if b1 > 4 then : b1 = 4 : end if
and repeat a similar scheme for any that remain.
yes I find out

it 2 year since i program picaxe last time, so need to get back all the syntax again :)

check my code in replay 7 i change it so nosyntax error now :)
 

Hansen

Member
Then PWN is on it make so much noice on c.1 that i use as touch,

i use it as "touch C.1,b7" the b7 has value 255 all the time, after pwmout turn on c.2

what can be the problem ????
 

nick12ab

Senior Member
what can be the problem ????
You're driving a MOSFET via PWM? Add a resistor between pin and MOSFET gate - I had to do the same when direct MOSFET connection caused interference on a serial LCD so it's probably the same issue with yours.
 

Hansen

Member
add 10k pull down as show in manual 3

I found out when PWM started the debug function freezer

I thing i may check the key function with normaly push key
 

nick12ab

Senior Member
Hansen, not between the gate and 0v, you remove the existing connection from the PICAXE pin to the gate of the MOSFET and reconnect using a 10k resistor. The direct connection will interfere with the sertxd just like it interfered with an AXE033 serial LCD. Have you also got decoupling capacitors (and don't put them anywhere unless you know where to put them, not guessed).
 

westaust55

Moderator
You should also include the #picaxe directive, which I've added.
Code:
' Base on  08M2  running in 2 task
' This is the controller & driver part 
' for the light control
        Symbol OnOff = C.0
        Symbol ALight = b0 ' actuel light level
        Symbol State = b1 
        let ALight = 0 ' value 0 to 4
        let State = 0 ' Value 0 to 4
        #picaxe 08M2    [B]'This should be required by international law[/B]
In much the same manner that it is your personal opinion that it should be &#8216;mandatory&#8217; for inclusion of the PE directive
#PICAXE <part No>​
I see that as a minor issue since:
1. The thread title indicates an 08M2 is involved
2. The first line in the code is a remark which indicates a 08M2 is involved.

In much the same manner it is my personal opinion/recommendation that where directives are going to be used, it is best to put them at the top of the code rather than below SYMBOL statements and various LET assignment commands/statements.
In that way they are easily found and where necessary altered or removed.
Imaging for example having to troll through hundreds of lines of program code to find a #NO_EEPROM directive or possibly scratching one's head wonding why the intended data is not put in the EEPROM memory on program download for and X1 or X2 parts.
 

nick12ab

Senior Member
It isn't only my personal preference but the comment was a reference to someone else's comment of 'it should be mandatory' before yours (it might have been MartinM57).

Imaging for example having to troll through hundreds of lines of program code to find a #NO_EEPROM
You use the find tool. I only put it there because I thought it looked strange to have it growing out of the bottom of the introductory paragraph - normally I put it at the top. The directive is helpful though when the PICAXE in use isn't clear and also to save having to open the Options dialog every time you want to change.
 
Last edited:

Hansen

Member
thx for all the replay :)

In test face i move the PWMOUT to another and make it controled by 1 pin to check my key routine maybe change touch function to normaly key bottom
 
Top