Day 2 - turning on an LED (the mircos 'hello world')

tinyb

Member
Yay day 2 has finally arrived - and you thought i ment i ws going to be chronological about it. The following diagram is the 3d blowout supplied by sparkfun (from the oomlet collection of files) and the breadboard layout image. This method is great for students and have tried it for some 555 circuits I am using at the moment in my intro to electronics course (learning the ins and outs of a breadboard).



Breadboard layout sheet

The blinking LED is easy:
Code:
'header to be included when i have finalised the look for all programs

#sim axe401			'for simulation - the board you are using
#picaxe28x2			'the picaxe chip installed in the picaxe shield base

symbol ledpin = s.13	'led connected to pin s.13

'this line added after help with day 3 - see the discussion when i publish it
dirS.13 = 1			'set s.13 as an output

do
	high ledpin		                'turn on the led
	pause 1000	                'wait 1 second (1000 milli seconds)
	low ledpin		                'turn off the led
	pause 1000		'wait 1 second
loop				'repeat
Then there is the making it better section:
changing the output pin
this id just a case of alerting the user that the 2 lines of code that need to be changed

symbol ledpin = S.newpin
and
dirS.newpin

and to physically move the LED to the new pin.

changing the blink time
this explaning the on and off time - the two pauses. that the time is in milliseconds, so 5 seconds would be 5000. that the max value is approx 65000 milli seconds. introduce the wait and nap commands and the pros and cons for each.

Control the brightness
This talks about along with on/off control (digital) you can also control some pins in an analogue (brightness) fashon.
Explain PWM and do it on s.9

Code:
'header to be included when i have finalised the look for all programs

#sim axe401			'for simulation - the board you are using
#picaxe28x2			'the picaxe chip installed in the picaxe shield base

symbol ledpin = s.9	'led connected to pin s.9

'this line added after help with day 3 - see the discussion when i publish it
dirS.9 = 1			'set s.9 as an output

init:
pwmout ledpin,150,150 	' set pwm duty

do
	pwmduty ledpin,150 	; set pwm duty - on full
	pause 1000 			; pause 1 s
	pwmduty ledpin,50 	; set pwm duty - not as bright
	pause 1000 			; pause 1 s
loop
Fading
This example uses a loop to increase the brightness then another to decrease it.

Code:
'header to be included when i have finalised the look for all programs

#sim axe401			'for simulation - the board you are using
#picaxe28x2			'the picaxe chip installed in the picaxe shield base

symbol ledpin = s.9	'led connected to pin s.9

'this line added after help with day 3 - see the discussion when i publish it
dirS.9 = 1			'set s.9 as an output

init:
pwmout ledpin,150,150 	' set pwm duty

do
	for b0 = 0 to 150 step 10
		pwmduty ledpin,b0 	; set pwm duty - on full
		pause 100 			; pause 100 ms
	next b0
	
	for b0 = 150 to 0 step -10
		pwmduty ledpin,50 	; set pwm duty - not as bright
		pause 100 			; pause 100 ms
	next b0
loop
the final part is to compare the original arduino 2 page spread and the new picaxe 2 page spread (sorry the image has not been up dated to the picaxe black - 1 cause i can't and 2 cause black on black doesn't work.

View attachment 10585
View attachment 10584

The text file of code can't uploaded as i can only upload 2 files i have put the final result below in the code tags.
Code:
tba
hope that you have enjoyed the first real programing day. tomorrow we turn to controlling 8 leds, now that was alearning curve for me - will point you to the forum post I made.

thanks
tiny
 

mrburnette

Senior Member
Very cool. Nice graphics, good format and content, and easy to read. I like the "Not working" section since statistically, it will be necessary. I've been building electronic kits since I was 12 (Knight Kit Span Master) and the exploded wiring diagram bring back old memories of this style of instruction... except back then, everything was B/W, no color!

Good job,

-Ray
 

tinyb

Member
mrburnette;bt157 said:
Very cool. Nice graphics, good format and content, and easy to read. I like the "Not working" section since statistically, it will be necessary. I've been building electronic kits since I was 12 (Knight Kit Span Master) and the exploded wiring diagram bring back old memories of this style of instruction... except back then, everything was B/W, no color!

Good job,

-Ray

can't take all the credit (very little really). this is work complete by the people over at oomlet and sparkfun. I am just changing it to a picaxe friendly version.

Glad you liked it - only another 13 to go.

thanks
tiny
 
Top