20x2 Led 4 Digit 7 Segment Metronome

marks

Senior Member
Have been waiting for some bits from futerlec for ages still havent received them
so my projects on hold.. was intrigued about what a metronome is
so i thought id hav a go
hope i get some feedback if its not quite right or if any1 can offer some suggestions
thanks in advance lol!

it will display the number pattern 1 2 3 4 across the four seqments.
it can also be set to 1 2 3 or display a 1 2 pattern.
at a rate that can be set between 30 beats per minute and 254 beats per minute.
When powered on it will display a 4 so u can see its been set to a 4 beat pattern.
push the button it will start at 60 beats per minute which has been preset.

if you hold on the button you can select from a menu (b,2,3,4,r)
push to cycle hold to select 2or 3 or 4 selects beat pattern.
hold on b(beats perminute) and will display 60 hold will exit a push enables you to select between30 and 254 hold and exit you can now use the new rates.
if we want to save the new setting select r(remember)in the menu and hold.
Code:
	'                     -- --   -- --  
	' B0-A             |       |       | |     |        Picaxe  20x2  ver C.0
	' B1-B	
	' B2-C             |       |       | |     |        Marks
	' B3-D                -- --   -- --   -- --
	' B4-E             | |             |       |
	' B5-F
	' B6-G             | |             |       |
	'                     -- --   -- --     
	'
	'Display        1       2       3       4
	'Common anode  C.3     C.2     C.1     C.0
	
	SYMBOL display1      = C.3     
	SYMBOL display2      = C.2
	SYMBOL display3      = C.1
	SYMBOL display4      = C.0
	SYMBOL DP            = A.0
	
	SYMBOL Pushbutton    = PINC.6
	
	SYMBOL Push          = B3
	SYMBOL Character     = B4
	SYMBOL Beat          = B5  '1 2 3 4 displayed beat
	SYMBOL BPM           = B6  '30 to 254
	SYMBOL NumberOfBeats = B7  '2or3or4 beat pattern 
	
	SYMBOL Hold          = W8
	SYMBOL BeatsPerMinute= W9  	
	SYMBOL BPMval1       = W10
	SYMBOL BPMval2       = W11
	
eeprom    0,(192,249,164,176,153,146,130,248,128,144,255)  'Character     ,(0,1,2,3,4,5,6,7,8,9,blank) 
eeprom   11,(131,164,176,153,175)                          'menu Character,(b,2,3,4,r)
eeprom   20,(60,4)                                         'bpm,beats

READ 20,BPM
READ 21,numberofbeats

main:
LET dirsb = %11111111
LET dirsc = %10111111

ConvertBPM: HIGH display3 : IF pushbutton = 1 THEN ConvertBPM
LET BeatsPerMinute = BPM                    '    BPM calculated at default 8mhz
BPMval1=50000 /BeatsPerMinute*30/4*5                   'calculate beats per minute
BPMval2=50000//BeatsPerMinute*30/4*5/BeatsPerMinute    'ie    250 beats per minute = 58036 
           BeatsPerMinute=BPMval1+BPMval2              'ie     30 beats per minute =  3036
           BeatsPerMinute=-BeatsPerMinute
      
Initialise: HIGH DP : hold=0 : push=0
SETTIMER BeatsPerMinute                                
TIMER = 0

BeatDisplay:
 beat=TIMER//numberofbeats                                    
                                                           
 IF beat = 0 THEN LET beat = NumberOfBeats : ENDIF

character = 10: IF beat <> 1 THEN dig1                                      ' blanking
   LET character = beat                                      
Dig1: HIGH display4 : READ character, pinsb : LOW display1 : PAUSE 1       'Display1 

IF pinc.6 = 1 THEN selection

character = 10: IF beat <> 2 THEN dig2                                      ' blanking 
   LET character = beat                                                                               
Dig2: HIGH display1 : READ character, pinsb : LOW display2 : PAUSE 1       'Display2 
	
character = 10: IF beat <> 3 then dig3                                      ' blanking
   LET character = beat 	 	                                   		
Dig3: HIGH display2 : READ character, pinsb : LOW display3 : PAUSE 1       'Display3
	
character = 10: IF beat <> 4 then dig4                                      ' blanking 
   LET character = beat 
Dig4: HIGH display3 : READ character, pinsb : LOW display4 : PAUSE 1       'Display4
 
ON push GOTO initialise,beatdisplay
                              
Selection:
IF hold > 800 THEN Menu
inc hold
IF pushbutton = 1 THEN selection
push = push + 1//2
ON push GOTO initialise,beatdisplay                                     
  
Menu:character = 11 :LOW DP : IF pushbutton = 1 THEN Menu 
 Men:hold=0
            READ character,pinsb : LOW display1 : PAUSE 1 : HIGH display1      
 	     	  PAUSE 2  	  	 
      IF pushbutton=0 THEN men                               'Display menu
                                                                      
    Menu1:HIGH display1
     IF hold > 700 then Menuselection                        'Hold to select
      INC hold
       LOW display1 : IF pushbutton = 1 THEN menu1

   INC character                                         'Roam menu on release
  IF character = 16 THEN menu                              
 GOTO men	

Menuselection:IF pushbutton = 1 THEN Menuselection
     SELECT CASE character
CASE 11 : GOTO BPMDisplay
CASE 12 TO 14 : LET numberofbeats = character-10  : GOTO initialise
CASE 15  : WRITE 20,BPM : WRITE 21,numberofbeats  : GOTO initialise
     END SELECT

BPMDisplay:HIGH a.0:hold =0
      LET character = BPM DIG 2 
          READ character ,pinsb           : LOW display1 : PAUSE 1 : HIGH display1   
 	    
	LET character = BPM DIG 1	                                          
          READ character,pinsb            : LOW display2 : PAUSE 1 : HIGH display2         
          
      LET character = BPM DIG 0			
          READ character,pinsb            : LOW display3 : PAUSE 1 : HIGH display3   
                
IF pinc.6 = 1 THEN selection1
 GOTO BPMDisplay
 
 Selection1:
IF hold > 800 THEN ConvertBPM
INC hold
IF pushbutton = 1 THEN selection1
 
 
   mselect: IF pushbutton = 1 THEN mselect : LET BPM = 0
             
      mselec: hold = 0  	         
                  LET character = BPM DIG 2	                                          
              READ character,pinsb : LOW display1 : PAUSE 1 : HIGH display1            
            IF pushbutton=0 THEN mselec
                                                                    
       msele:low display1 : IF hold > 700 then mslect                    
              INC hold  :  HIGH display1
            IF pushbutton = 1 THEN msele
      
      BPM = BPM + 100                                        
      IF character = 3 THEN mselect                         
      GOTO mselec
      
                    mslect:LET BPMval2 = BPM : IF BPM < 100 THEN LET BPMval2=30 : ENDIF
                    HIGH display1 :IF pushbutton = 1 THEN mslect
                                
                     mslec:hold = 0                                  
                            LET character = BPM DIG 2	            
                        READ character,pinsb  : LOW display1 : PAUSE 1 : HIGH display1  
          
                            LET character = BPMval2  DIG 1 			
                        READ character,pinsb  : LOW display2 : PAUSE 1 : HIGH display2        
                      IF pushbutton=0 THEN mslec
                                                                
                      msle:low display2 : IF hold > 700 THEN mmselect          
                             INC hold  :  HIGH display2
                           IF pushbutton = 1 THEN msle   
                       BPMval2 = BPMval2 + 10
                      IF character = 9 or bpmval2 > 250  THEN  mslect                              
                     GOTO mslec              
 	
    mmselect: LET BPM = BPMval2 : HIGH display2 : IF pushbutton = 1 THEN mmselect
                
     mmselec: hold = 0
                  LET character = BPM DIG 2	                                          
              READ character,pinsb  : LOW display1 : PAUSE 1 : HIGH display1  
          
                  LET character = BPM DIG 1 			
              READ character,pinsb  : LOW display2 : PAUSE 1 : HIGH display2        
            	         
                  LET character = BPM DIG 0	                                          
              READ character,pinsb  : LOW display3 : PAUSE 1 : HIGH display3            
            IF pushbutton=0 THEN mmselec
                                                                    
       mmsele:low display3 : IF hold > 700 then ConvertBPM                     
              INC hold  :  HIGH display3
              IF pushbutton = 1 THEN mmsele
      
     INC BPM                                            
     IF character = 9  or BPM = 255 THEN mmselect                              
     GOTO mmselec
just using the basic hardware setup i use for most my code examples .
 

Attachments

Last edited:

william47316

New Member
looks good, does the display get flickery at all multiplexing off the picaxe like that?
i have actually managed to drive 8 seven segment displays of a 08M with nil flicker and a maximum update rate of about 3.2 Hz (<180BPM), using 4800baud serial and standard ASCII for control. you send it 8 byte data bursts with a minimum pause between updates of about 315mS so you can get it to display the BPM setting the beat its on and use the bell character to indicate start of a segment using a pezio on the picaxe direct for marking the beat then you have plenty of IO's left (and probably space too) for pushbuttons or other timing critical stuff freeing the picaxe from driving the displays
 

marks

Senior Member
Hi Will,
theres no noticable flicker driving 4 segments at 8mhz
i needed to run at this speed to get the low beat rate of 30 BPM using set timer.

I have run upto 6 segments this way at 8mhz slight flicker
but increasing to 16 mhz speed is sweet as..
but you need the blue leds to do this to, to maintain good brightness
keeping around the 90ma mark the limit of the 20x2.
I have pushed the 20x2 a lot further tho amazed i havent killed it yet.

i noticed futerlec have some blue 1 inch displays which are on my christmas wish list
if i can wait that long lol! proberly drive them through a uln2803 taking the load of the picaxe
undecided whether to go 4 or 6 digit for an outside clock have been playing and the seconds are a bit gimmicky.

i'll proberly try 7 and 8 segments later on as could be handy to drive indiviual displays
of say amps and volts from 0ne picaxe. I do hate buttons tho using just 1 does use up a bit of code but even if we have more buttons we can only push one at a time lol.
IO's havent been a problem yet and theres still a few multiplexin tricks we can use for that.
 
Top