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.
tags please[/b]
Please use [PLAIN][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
?????????????My 4 If don't work with 3 ask
Thx for advicesymbol 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:
' 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
it was the 4 line with "if b3 = 1 and b5 = 0 and OnOff =0 then" find out it not alow to have 3 option( 3 variable ) in the same IF?????????????
yes I find outYou can only use (goto) label after an IF without ENDIF. UseCode:if b1 > 4 then b1 = 0
and repeat a similar scheme for any that remain.Code:if b1 > 4 then : b1 = 4 : end if
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.what can be the problem ????
alsoYou can only use (goto) label after an IF without ENDIF.
And not forgetting 'if...then exit' for getting out of loops!also
GOSUB <label>
In much the same manner that it is your personal opinion that it should be ‘mandatory’ for inclusion of the PE directiveYou 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]
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.Imaging for example having to troll through hundreds of lines of program code to find a #NO_EEPROM