I have an idea....but I'd welcome your input

radiogareth

Senior Member
Those of you with any Android based phone or tablet will probably be familiar with the rotary icon showing that there is a process underway (downloads etc). Its not easy to describe, but is basically two running 'lights' one going clockwise and one going anticlockwise with a fading trail.

I fancy trying that with a 20M2 and 16 bi-colour LEDs in a circle. Why? It would be visually interesting :)

The fade bit could be done with a capacitor on each LED feed (might need steering diodes to work) but I'm struggling to envisage how the code might be constructed. A single running circle would be easy, but two in antiphase with phase shift between them....yikes!!

Something involving pulseout and counting up/down might work, at least as starters. The KITT car scanner light (beloved of electronic projects 20+ years ago) would be quite easy to start with, especially with hardware-based fade function.

Things I can see I need - a way of 'joining' both ports (b0-b7&C0-c7) together so it appears like a single 16 bit one and can be addressed as such would be a good start.

Any thoughts???
 

Haku

Senior Member
Ages ago I replaced the rubbish 5 LED scanner on an RC KITT with an 8 LED setup that simulates a fading trail running from an 18X:



The code uses pulsout to do rudimentary PWM, which when you're looking at it straight on you can't see the flicker but if you dart your eyes across you see dot & dash trails from the LEDs (like you do with LED alarm clocks). I tried it on an M2 chip running at 32mhz and the effect is a lot better as the light pulses are reduced to 1/4 and the pawz symbol is increased to compensate. One day I'll try it on a Picaxe running at 64mhz:
Code:
#picaxe 18x

'KITT scanning light

symbol pawz=24
symbol z1=255
symbol z2=100
symbol z3=33
symbol z4=7
symbol z5=1
setfreq m8


do
 for b0=0 to pawz:pulsout 0,z1:pulsout 1,z2:pulsout 2,z3:pulsout 3,z4:pulsout 4,z5:next b0
 for b0=0 to pawz:pulsout 1,z1:pulsout 0,z2:pulsout 1,z3:pulsout 2,z4:pulsout 3,z5:next b0
 for b0=0 to pawz:pulsout 2,z1:pulsout 1,z2:pulsout 0,z3:pulsout 1,z4:pulsout 2,z5:next b0
 for b0=0 to pawz:pulsout 3,z1:pulsout 2,z2:pulsout 1,z3:pulsout 0,z4:pulsout 1,z5:next b0
 for b0=0 to pawz:pulsout 4,z1:pulsout 3,z2:pulsout 2,z3:pulsout 1,z4:pulsout 0,z5:next b0
 for b0=0 to pawz:pulsout 5,z1:pulsout 4,z2:pulsout 3,z3:pulsout 2,z4:pulsout 1,z5:next b0
 for b0=0 to pawz:pulsout 6,z1:pulsout 5,z2:pulsout 4,z3:pulsout 3,z4:pulsout 2,z5:next b0
 for b0=0 to pawz:pulsout 7,z1:pulsout 6,z2:pulsout 5,z3:pulsout 4,z4:pulsout 3,z5:next b0
 for b0=0 to pawz:pulsout 6,z1:pulsout 7,z2:pulsout 6,z3:pulsout 5,z4:pulsout 4,z5:next b0
 for b0=0 to pawz:pulsout 5,z1:pulsout 6,z2:pulsout 7,z3:pulsout 6,z4:pulsout 5,z5:next b0
 for b0=0 to pawz:pulsout 4,z1:pulsout 5,z2:pulsout 6,z3:pulsout 7,z4:pulsout 6,z5:next b0
 for b0=0 to pawz:pulsout 3,z1:pulsout 4,z2:pulsout 5,z3:pulsout 6,z4:pulsout 7,z5:next b0
 for b0=0 to pawz:pulsout 2,z1:pulsout 3,z2:pulsout 4,z3:pulsout 5,z4:pulsout 6,z5:next b0
 for b0=0 to pawz:pulsout 1,z1:pulsout 2,z2:pulsout 3,z3:pulsout 4,z4:pulsout 5,z5:next b0
loop
It uses very little power as only 1 LED is ever on at any given time.

On the 20m2 pin 4 (c.6) is input only so you can't put an LED on each pin of the B & C ports, you'll have to do some charlieplexing to get 16 LEDs, or use less LEDs for them to all be directly driven by the 20m2.
 

radiogareth

Senior Member
Thanks, that pulsout is worth its weight in, well, pwm modulators ;-)

Got another one like that from this forum running 3 leds on an 08M2. Very nice :)

Really rather neat coding - I have 8 LEDs on a 14M2 and I'll try getting it to run on that later....
 
Last edited:

radiogareth

Senior Member
Well that was easier than I expected :)

Apart from changing the top two bits of port B which don't exist to the bottom two of Port C, using that faster clock etc, sorted :)

Don't think I'll be trying it with my original suggestion just yet though!

Code:
#picaxe 14m2

	dirsB = %00111111		'sets up port B
	dirsC = %00000011		'sets up port C Bits 0 & 1 Output
	
'KITT scanning light posted by Haku
'adapted to 14M2 by Radiogareth 12/4/2013
'Using PIGGYMIDDLE Motherboard
'with Piggyaxe Binary Timery PCB
'see www.g4xat.co.uk

	'This code by Haku
symbol pawz=96 'upped from 24
symbol z1=255
symbol z2=100
symbol z3=33
symbol z4=7
symbol z5=1
setfreq m32	'upped from M8 - we have the processor power!

'changed ref to each pin 6 & 7 to C.0,C.1 to complete the chain
do
 for b0=0 to pawz:pulsout b.0,z1:pulsout b.1,z2:pulsout b.2,z3:pulsout b.3,z4:pulsout b.4,z5:next b0
 for b0=0 to pawz:pulsout b.1,z1:pulsout b.0,z2:pulsout b.1,z3:pulsout b.2,z4:pulsout b.3,z5:next b0
 for b0=0 to pawz:pulsout b.2,z1:pulsout b.1,z2:pulsout b.0,z3:pulsout b.1,z4:pulsout b.2,z5:next b0
 for b0=0 to pawz:pulsout b.3,z1:pulsout b.2,z2:pulsout b.1,z3:pulsout b.0,z4:pulsout b.1,z5:next b0
 for b0=0 to pawz:pulsout b.4,z1:pulsout b.3,z2:pulsout b.2,z3:pulsout b.1,z4:pulsout b.0,z5:next b0
 for b0=0 to pawz:pulsout b.5,z1:pulsout b.4,z2:pulsout b.3,z3:pulsout b.2,z4:pulsout b.1,z5:next b0
 for b0=0 to pawz:pulsout c.0,z1:pulsout b.5,z2:pulsout b.4,z3:pulsout b.3,z4:pulsout b.2,z5:next b0
 for b0=0 to pawz:pulsout c.1,z1:pulsout c.0,z2:pulsout b.5,z3:pulsout b.4,z4:pulsout b.3,z5:next b0
 for b0=0 to pawz:pulsout c.0,z1:pulsout c.1,z2:pulsout c.1,z3:pulsout b.5,z4:pulsout b.4,z5:next b0
 for b0=0 to pawz:pulsout b.5,z1:pulsout c.0,z2:pulsout c.1,z3:pulsout c.0,z4:pulsout 5,z5:next b0
 for b0=0 to pawz:pulsout b.4,z1:pulsout b.5,z2:pulsout c.0,z3:pulsout c.1,z4:pulsout c.0,z5:next b0
 for b0=0 to pawz:pulsout b.3,z1:pulsout b.4,z2:pulsout b.5,z3:pulsout c.0,z4:pulsout c.1,z5:next b0
 for b0=0 to pawz:pulsout b.2,z1:pulsout b.3,z2:pulsout b.4,z3:pulsout b.5,z4:pulsout c.0,z5:next b0
 for b0=0 to pawz:pulsout b.1,z1:pulsout b.2,z2:pulsout b.3,z3:pulsout b.4,z4:pulsout b.5,z5:next b0
loop
Thanks again Haku

Gareth
 

westaust55

Moderator
I think a couple of corrections are required (see red edits in code):

Code:
#picaxe 14m2

	dirsB = %00111111		'sets up port B
	dirsC = %00000011		'sets up port C Bits 0 & 1 Output
	
'KITT scanning light posted by Haku
'adapted to 14M2 by Radiogareth 12/4/2013
'Using PIGGYMIDDLE Motherboard
'with Piggyaxe Binary Timery PCB
'see www.g4xat.co.uk

	'This code by Haku
symbol pawz=96 'upped from 24
symbol z1=255
symbol z2=100
symbol z3=33
symbol z4=7
symbol z5=1
setfreq m32	'upped from M8 - we have the processor power!

'changed ref to each pin 6 & 7 to C.0,C.1 to complete the chain
do
 for b0=0 to pawz:pulsout b.0,z1:pulsout b.1,z2:pulsout b.2,z3:pulsout b.3,z4:pulsout b.4,z5:next b0
 for b0=0 to pawz:pulsout b.1,z1:pulsout b.0,z2:pulsout b.1,z3:pulsout b.2,z4:pulsout b.3,z5:next b0
 for b0=0 to pawz:pulsout b.2,z1:pulsout b.1,z2:pulsout b.0,z3:pulsout b.1,z4:pulsout b.2,z5:next b0
 for b0=0 to pawz:pulsout b.3,z1:pulsout b.2,z2:pulsout b.1,z3:pulsout b.0,z4:pulsout b.1,z5:next b0
 for b0=0 to pawz:pulsout b.4,z1:pulsout b.3,z2:pulsout b.2,z3:pulsout b.1,z4:pulsout b.0,z5:next b0
 for b0=0 to pawz:pulsout b.5,z1:pulsout b.4,z2:pulsout b.3,z3:pulsout b.2,z4:pulsout b.1,z5:next b0
 for b0=0 to pawz:pulsout c.0,z1:pulsout b.5,z2:pulsout b.4,z3:pulsout b.3,z4:pulsout b.2,z5:next b0
 for b0=0 to pawz:pulsout c.1,z1:pulsout c.0,z2:pulsout b.5,z3:pulsout b.4,z4:pulsout b.3,z5:next b0
 for b0=0 to pawz:pulsout c.0,z1:pulsout c.1,z2:pulsout c.[B][COLOR="#FF0000"]0[/COLOR][/B],z3:pulsout b.5,z4:pulsout b.4,z5:next b0
 for b0=0 to pawz:pulsout b.5,z1:pulsout c.0,z2:pulsout c.1,z3:pulsout c.0,z4:pulsout [B][COLOR="#FF0000"]b.[/COLOR][/B]5,z5:next b0
 for b0=0 to pawz:pulsout b.4,z1:pulsout b.5,z2:pulsout c.0,z3:pulsout c.1,z4:pulsout c.0,z5:next b0
 for b0=0 to pawz:pulsout b.3,z1:pulsout b.4,z2:pulsout b.5,z3:pulsout c.0,z4:pulsout c.1,z5:next b0
 for b0=0 to pawz:pulsout b.2,z1:pulsout b.3,z2:pulsout b.4,z3:pulsout b.5,z4:pulsout c.0,z5:next b0
 for b0=0 to pawz:pulsout b.1,z1:pulsout b.2,z2:pulsout b.3,z3:pulsout b.4,z4:pulsout b.5,z5:next b0
loop
 

radiogareth

Senior Member
Thanks for the eagle eyes Westaust55. The software worked without naming the B port pins which surprised me. The C0 was a typo.
I have added a readadc to control the speed (because my board alrady had one there), it really needs a bottom end 'trap' to stop it going toooo fast, but that can wait.
Code:
'*******************************************************
'* Sample PICAXE Software for use with PICAXE Micros   *
'* For educational use only. By R G Evans, E & OE      * 
'* known as Gareth or radiogareth on Picaxe Forum      *
'* For more information and PCBs visit www.g4xat.co.uk *
'* Part of the PIGGYAXE family of interesting apps!	 *
'* 8 LEDs on the Binary_Timery PIGGYAXE Board          *
'* This version RGE#1.0 written 12/4/2013              *
'* Based on code by Haku 12/4/2013 on the PicaxeForum  *
'*******************************************************
#picaxe 14m2			'Defines processor
	dirsB = %00111111		'sets up port B
	dirsC = %00000011		'sets up port C Bits 0 & 1 Output	
'KITT scanning light originally posted by Haku
'Using PIGGYMIDDLE Motherboard 14M2 @ 32 MHz
'with Piggyaxe Binary Timery PCB - speed control possible via ADC
'see www.g4xat.co.uk for lots more information
'readadc c.4,b1
'symbol pawz=b1 'upped from 24 @ 8MHz
symbol z1=255
symbol z2=100
symbol z3=33
symbol z4=7
symbol z5=1
setfreq m32	'upped from M8 - we have the processor power!
'A long sequence of pulseout commands using differetn proportions, stepping through the 8 LEDs
do	'Start of loop
 readadc c.4,b1:symbol pawz=b1	'allows you to choose the "KITT" speed from bullet to "slug"!
 for b0=0 to pawz:pulsout b.0,z1:pulsout b.1,z2:pulsout b.2,z3:pulsout b.3,z4:pulsout b.4,z5:next b0
 for b0=0 to pawz:pulsout b.1,z1:pulsout b.0,z2:pulsout b.1,z3:pulsout b.2,z4:pulsout b.3,z5:next b0
 for b0=0 to pawz:pulsout b.2,z1:pulsout b.1,z2:pulsout b.0,z3:pulsout b.1,z4:pulsout b.2,z5:next b0
 for b0=0 to pawz:pulsout b.3,z1:pulsout b.2,z2:pulsout b.1,z3:pulsout b.0,z4:pulsout b.1,z5:next b0
 for b0=0 to pawz:pulsout b.4,z1:pulsout b.3,z2:pulsout b.2,z3:pulsout b.1,z4:pulsout b.0,z5:next b0
 for b0=0 to pawz:pulsout b.5,z1:pulsout b.4,z2:pulsout b.3,z3:pulsout b.2,z4:pulsout b.1,z5:next b0
 for b0=0 to pawz:pulsout c.0,z1:pulsout b.5,z2:pulsout b.4,z3:pulsout b.3,z4:pulsout b.2,z5:next b0
 for b0=0 to pawz:pulsout c.1,z1:pulsout c.0,z2:pulsout b.5,z3:pulsout b.4,z4:pulsout b.3,z5:next b0
 for b0=0 to pawz:pulsout c.0,z1:pulsout c.1,z2:pulsout c.0,z3:pulsout b.5,z4:pulsout b.4,z5:next b0
 for b0=0 to pawz:pulsout b.5,z1:pulsout c.0,z2:pulsout c.1,z3:pulsout c.0,z4:pulsout b.5,z5:next b0
 for b0=0 to pawz:pulsout b.4,z1:pulsout b.5,z2:pulsout c.0,z3:pulsout c.1,z4:pulsout c.0,z5:next b0
 for b0=0 to pawz:pulsout b.3,z1:pulsout b.4,z2:pulsout b.5,z3:pulsout c.0,z4:pulsout c.1,z5:next b0
 for b0=0 to pawz:pulsout b.2,z1:pulsout b.3,z2:pulsout b.4,z3:pulsout b.5,z4:pulsout c.0,z5:next b0
 for b0=0 to pawz:pulsout b.1,z1:pulsout b.2,z2:pulsout b.3,z3:pulsout b.4,z4:pulsout b.5,z5:next b0
 'could put in a check for input on a pin here to jump out and set speed
loop 'end of loop
 

westaust55

Moderator
the port.pin nomenclature are in fact pre-defined constants wher
B.0 = 0, B.1 = 1, . . . B.7 = 7
C.0 = 8, C.1 =9, . . . C.7 = 15
and so on for other ports as and when they exist on various larger chips.

Hence by default 5 instead of B.5 will still work but for consitency better to stick with the full port.pin nomenclature.
Had for example you left the "C," from C.1 then you would have seen a hiccup in the display even thouhgh syntax wise it work be okay and work.

For your setting of a max speed, ie minimum pause delay then either add a value as an offset or use the MIN math function so low/short values are set to a default minimum.
 

radiogareth

Senior Member
After watching the display I realised that c.0 and c.1 were transposed (pcb order). This version sorted, along with Westaust55's suggestion about including a 'min' to limit the highest speed to something that remains recognisable. This version includes the fixes and changes.
Code:
'*******************************************************
'* Sample PICAXE Software for use with PICAXE Micros   *
'* For educational use only. By R G Evans, E & OE      * 
'* known as Gareth or radiogareth on Picaxe Forum      *
'* For more information and PCBs visit www.g4xat.co.uk *
'* Part of the PIGGYAXE family of interesting apps!	 *
'* 8 LEDs on the Binary_Timery PIGGYAXE Board          *
'* This version RGE#1.0 written 12/4/2013              *
'* Based on code by Haku 12/4/2013 on the PicaxeForum  *
'*******************************************************
#picaxe 14m2			'Defines processor
	dirsB = %00111111		'sets up port B
	dirsC = %00000011		'sets up port C Bits 0 & 1 Output	
'KITT scanning light originally posted by Haku
'Using PIGGYMIDDLE Motherboard 14M2 @ 32 MHz
'with Piggyaxe Binary Timery PCB - speed control possible via ADC
'see www.g4xat.co.uk for lots more information
'readadc c.4,b1
'symbol pawz=b1 'upped from 24 @ 8MHz
symbol z1=255
symbol z2=100
symbol z3=33
symbol z4=7
symbol z5=1
setfreq m32	'upped from M8 - we have the processor power!
'A long sequence of pulseout commands using differetn proportions, stepping through the 8 LEDs
do	'Start of loop
 readadc c.4,b2:b1=b2 min 30:symbol pawz=b1	'allows you to choose the "KITT" speed from 'bullet' to "slug"!
 'added min 30 to ensure even at its fastest its still clear to see what it it. Thanks Westaust55
 for b0=0 to pawz:pulsout b.0,z1:pulsout b.1,z2:pulsout b.2,z3:pulsout b.3,z4:pulsout b.4,z5:next b0
 for b0=0 to pawz:pulsout b.1,z1:pulsout b.0,z2:pulsout b.1,z3:pulsout b.2,z4:pulsout b.3,z5:next b0
 for b0=0 to pawz:pulsout b.2,z1:pulsout b.1,z2:pulsout b.0,z3:pulsout b.1,z4:pulsout b.2,z5:next b0
 for b0=0 to pawz:pulsout b.3,z1:pulsout b.2,z2:pulsout b.1,z3:pulsout b.0,z4:pulsout b.1,z5:next b0
 for b0=0 to pawz:pulsout b.4,z1:pulsout b.3,z2:pulsout b.2,z3:pulsout b.1,z4:pulsout b.0,z5:next b0
 for b0=0 to pawz:pulsout b.5,z1:pulsout b.4,z2:pulsout b.3,z3:pulsout b.2,z4:pulsout b.1,z5:next b0
 for b0=0 to pawz:pulsout c.1,z1:pulsout b.5,z2:pulsout b.4,z3:pulsout b.3,z4:pulsout b.2,z5:next b0
 for b0=0 to pawz:pulsout c.0,z1:pulsout c.1,z2:pulsout b.5,z3:pulsout b.4,z4:pulsout b.3,z5:next b0
 for b0=0 to pawz:pulsout c.1,z1:pulsout c.0,z2:pulsout c.1,z3:pulsout b.5,z4:pulsout b.4,z5:next b0
 for b0=0 to pawz:pulsout b.5,z1:pulsout c.1,z2:pulsout c.0,z3:pulsout c.1,z4:pulsout b.5,z5:next b0
 for b0=0 to pawz:pulsout b.4,z1:pulsout b.5,z2:pulsout c.1,z3:pulsout c.0,z4:pulsout c.1,z5:next b0
 for b0=0 to pawz:pulsout b.3,z1:pulsout b.4,z2:pulsout b.5,z3:pulsout c.1,z4:pulsout c.0,z5:next b0
 for b0=0 to pawz:pulsout b.2,z1:pulsout b.3,z2:pulsout b.4,z3:pulsout b.5,z4:pulsout c.1,z5:next b0
 for b0=0 to pawz:pulsout b.1,z1:pulsout b.2,z2:pulsout b.3,z3:pulsout b.4,z4:pulsout b.5,z5:next b0
loop 'end of loop
Thanks - all I need now is a KITT sound effect as a Picaxe tune file......
 
Top