Gramps
Senior Member
This should be so simple but it will not work!
Mr. Lofton's code from years ago using a 18M2 part.
I changed to 28X2 part (and changed pin numbers, ofcourse)
Test results;
LED lights about half brightness but pot does not change brightness.
Mr. Lofton's code from years ago using a 18M2 part.
I changed to 28X2 part (and changed pin numbers, ofcourse)
Test results;
LED lights about half brightness but pot does not change brightness.
Code:
;Lewis Lofton's code at: https://www.youtube.com/watch?v=qY_kpREPTb4&pp=ygUQbGV3aXMgbG9mbGluIHB3bQ%3D%3D
;He used an 18M2 part
;The program below uses three commands. Pwmout sets up B.3 for a 1000Hz 50 percent duty cycle square wave. Readadc10 reads the position of a 5k or 10k control connected to B.4 and returns a value from 0-1023. Val must be a 16-bit "word" variable. The command "pwmduty" alters the duty cycle of the square wave from B.3 "on the fly" that is without turning it off and resetting the whole sequence. The higher the duty cycle the faster the motor should run. (Or brighter the LED.)
#picaxe 28X2
#no_data
#no_table
symbol speed_control = B.2
symbol val = w0 ; word (16-bit) user variable
symbol pwmPin = C.1
init:
pwmout C.1, 199, 399
main:
readadc10 speed_control, val
; read 10-bit ADC into variable w0
pwmduty pwmPin, val ; set pwm duty
goto main ; loop back to start
[code/]