18M2 Analouge inputs

Status
Not open for further replies.

Symon20

New Member
hey,
i am currently attempting to make a light for wich the program for it is as the surrounding light drops it take the ouput from the Light sensor, and them puts the same volatge from the output, however if i high pulse is given from a switch put into a different input leg, however the end result is just the light on full the entire time

my program currently is
main:

prog: if pinc.2 = 1 then push

readadc c.1, b0
if b0 > 30 then lux
debug

goto main


push:
high b1
b1=255
wait 1
for b1=255 to 0 step - 2
pwmout 3,255,b1
if b0=b1 then goto main '
pause 10
next

Lux:
let pinc.7 = b0

goto main


Any help would be greatly apprceiated

symon20
 

MPep

Senior Member
Consider the fllowing:
How can
Code:
readadc c.1, b0
	if b0 > 30 then lux
..
..
..
Lux:
let pinc.7 = b0
when B0 can be any value between 301 and 255 ????????
 

westaust55

Moderator
Welcome to the PICAXE forum.

It would be better if you used some punctuation and described step by step exactly how you what your project to work.

Also it is good practice when posting code to use the [code] and [/code] tags around your code if more than a few lines so it appears in a sub window.

Some indenting of the code (see attached reformat of your code) and comments describing what you are trying to do on each line can help others understand what you are trying to do.

Code:
main:

prog:
	if pinc.2 = 1 then push [COLOR="#006400"]; if the switch is pressed then . . . .[/COLOR]

	readadc c.1, b0
	if b0 > 30 then lux
	debug

	goto main


push:
	high b1
	b1=255
	wait 1
	for b1=255 to 0 step - 2
		pwmout [B][COLOR="#FF0000"]B.[/COLOR][/B]3,255,b1
		if b0=b1 then goto main '
		pause 10
	next

Lux:
	let pinc.7 = b0
	goto main
 

westaust55

Moderator
And, further to what MPep has indicated,

When the switch on pin C.2 is activated you are outputting a PWM signal on in B.3

pwmout 3,255,b1 - note that pin 3 is pin B.3 - better to use the port.pin notation as B.3 with X2 and M2 PICAXE parts

Yet after the READADC command you are trying to output to pin C.7 with the line
let pinc.7 = b0

Albeit as MPep indicates, a pin can only be assigned a value 0f 0 or 1 so the line let pinc.7 = b0 only uses the least significant bit of variable b0.
 

Symon20

New Member
thankyou for the help so far i am editing my program at the moment to what you have stated,
what i would like my program to do is for the pic to give the same output the the Light Sensor thus changing the brightness of the Luxeon connected at the final output,
however if a switch is pressed at a seperate input of the pic, the program will then switch over to a setting where the light will come on for around 5-10 seconds at full power and then start to gradually get dimmer until it reaches the same brightness level as if it were going through the Light Sensor. once it reaches that point i should then flick back to the light sensor 'section' of the program

again all help is greatly appreciated,

Regards
Symon20
 
Status
Not open for further replies.
Top