Countdown Timer using OLED

dbarry722

Member
Hi Folks..

Just looking at expanding the Countdown timer from Marks that uses seven segment LED's. Has anyone attempted to use an OLED as the display unit?

If so, does anyone have sample code to demonstrate this on an OLED

Regards

Declan
 

bfgstew

Senior Member
I am currently writing a code for a countdown timer, it is only running in simulation at the moment and still needds a few loose ends tidying up, but it does what I ask of it.
Unfortunately I cannot post the code at the moment as on works PC, so unless someone does I can post later on this evening.
It is for counting down 2 events, the first to send a pin high, the second is an interval time before repeating the cycle until a set number of cycles has been reached. It displays the time on the 20 X 4 OLED.

Stewart
 

bfgstew

Senior Member
Declan,
Jetdev, posted me this code to get me going -
setfreq em16

symbol mins = b0
symbol hrs = b1
symbol days = b2

symbol set_sec = b3
symbol set_mins = b4
symbol set_hrs = b5
symbol set_days = b6

settimer t1s_16

time_loop:
if timer = set_sec and mins = set_mins and hrs = set_hrs and days = set_days then gosub trigger
if timer = 60 then inc mins:let timer = 0:endif
if mins = 60 then inc hrs:let mins = 0:endif
if hrs = 24 then inc days:let hrs = 0:endif
goto time_loop

trigger:
settimer off
'do stuff here
let timer = 0
settimer t1s_16
return

It just needed reversing and adding the serout commands to send to the OLED, have a play with this until I can post mine, best way of learning is having a crack at it.

Stewart
 

dbarry722

Member
Hi Stewart..

Cheers. Many thanks for that. Will look forward to your code later on to see if I can fit in into my scenario.

Declan
 

bfgstew

Senior Member
Declan

This is my code, its set for a 28X2 chip, it for setting hrs, mins and secs using a 4X3 keypad. You may have to jig bits around for what you need but if you run it innsimulation you will get an idea how it runs. Good luck.

Code:
SET_EXPO:
	let b7 = 0
	let b6 = 0
	let b5 = 0
	let b33 = 0	
	serout C.3,N9600_16,(254,1)
		pause 500
			serout C.3,N9600_16,(254,128,"SET EXPOSURE TIME")      ; sets the exposure time in hh/mm/ss format
			serout C.3,N9600_16,(254,194,#b7,"  hours")
			serout C.3,N9600_16,(254,150,#b6,"  minutes")
			serout C.3,N9600_16,(254,214,#b5,"  seconds")
			pause 100
		gosub V7
	pause 100
	gosub V6
	pause 100
	gosub V5
	pause 100
	goto SET_INT
V7:	
									;V7,V6 and V5 are the variables
	for b33 = 1 to 2								; for the exposure times			
  		gosub GKP
  			if key_value = 12 then let b7 = 0 return  endif	;if no value wanted key in 12
  			if key_value = 11 then let b7 = 0 
  			endif
  			if key_value = 10 then goto SET_EXPO 					 ;if incorrect key in 10 and go back to start 
  			b7 = b7 * 10 + b1
  			if b7 < 10 then serout C.3,N9600_16,(254,194,"0",254,195,#b7) else
  			serout C.3,N9600_16,(254,194,#b7) endif
  		pause 30
  	next b33
  	return
  	
V6:
	for b33 = 1 to 2				
  		gosub GKP
  			if key_value = 12 then let b6 = 0 return  endif
  			if key_value = 11 then let b6 = 0
  			endif
  			if key_value = 10 then goto SET_EXPO 
  			b6 = b6 * 10 + b1
  			if b6 < 10 then serout C.3,N9600_16,(254,150,"0",254,151,#b6) else
  			serout C.3,N9600_16,(254,150,#b6) endif
  		pause 30
  	next b33
  	return
  	
V5:
	for b33 = 1 to 2				
  		gosub GKP
  			if key_value = 12 then let b5 = 0 return  endif
  			if key_value = 11 then let b5 = 0
  			endif
  			if key_value = 10 then goto SET_EXPO  
  			b5 = b5 * 10 + b1
  			if b5 < 10 then serout C.3,N9600_16,(254,214,"0",254,215,#b5) else
  			serout C.3,N9600_16,(254,214,#b5) endif
  		pause 30
  	next b33
  	return
  	
  	

 		

 		
SET_INT:
	let b14 = 0	
	let b13 = 0
	let b12 = 0	
	let b33 = 0					; sets the interval time in hh/mm/ss format
	serout C.3,N9600_16,(254,1)
		pause 500
			serout C.3,N9600_16,(254,128,"SET INTERVAL TIME")
			serout C.3,N9600_16,(254,194,#b14,"  hours")
			serout C.3,N9600_16,(254,150,#b13,"  minutes")
	      	serout C.3,N9600_16,(254,214,#b12,"  seconds")
			pause 100
		gosub V14
	pause 100
	gosub V13
	pause 100
	gosub V12;
	pause 100
	goto FRAMESET 
V14:	
				;V14, V13 and V12 are the variables
 	for b33 = 1 to 2			; for the interval times			
  		gosub GKP
  			if key_value = 12 then let b14 = 0 return  endif
  			if key_value = 11 then let b14 = 0
  			endif
  			if key_value = 10 then goto SET_INT 
  			b14 = b14 * 10 + b1
  			if b14 < 10 then serout C.3,N9600_16,(254,194,"0",254,195,#b14) else
  		serout C.3,N9600_16,(254,194,#b14) endif
  	pause 30
  		next b33
  		return
  		
V13:
 	for b33 = 1 to 2				
  		gosub GKP
  			if key_value = 12 then let b13 = 0 return  endif
  			if key_value = 11 then let b13 = 0
  			endif
  			if key_value = 10 then goto SET_INT
  			b13 = b13 * 10 + b1
  			if b13 < 10 then serout C.3,N9600_16,(254,150,"0",254,151,#b13) else
  		serout C.3,N9600_16,(254,150,#b13) endif
  	pause 30
  		next b33
  		return
  		
V12:
 	for b33 = 1 to 2				
  		gosub GKP
  		if key_value = 12 then let b12 = 0 return  endif
  			if key_value = 11 then let b12 = 0
  			endif
  			if key_value = 10 then goto SET_INT 
  			b12 = b12 * 10 + b1
  			if b12 < 10 then serout C.3,N9600_16,(254,214,"0",254,215,#b12) else
  		serout C.3,N9600_16,(254,214,#b12) endif
  	pause 30
  		next b33
  		return

 		 		
FRAMESET:				; sets the number of exposures wanted
	let w14 = 0
	let b33 = 0
	 pause 50
		serout C.3,N9600_16,(254,1)
			pause 500
			serout C.3,N9600_16,(254,128,"SET HOW MANY")
			serout C.3,N9600_16,(254,192," EXPOSURES")
			serout C.3,N9600_16,(254,151,#w14)
			pause 100
		gosub VW14
	pause 100
	goto SETRUN
			
VW14:						;VW14 is the variable for amount of exposures
 	for b33 = 1 to 4				
  		gosub GKP
  		if key_value = 12 then let w14 = 0 return  endif
  			if key_value = 11 then let w14 = 0
  			endif
  			if key_value = 10 then goto FRAMESET 
  					w14 = w14 * 10 + b1
  				serout C.3,N9600_16,(254,154,#w14)
  			pause 30
  		next b33
 	Return
	
SETRUN:		;shows the times inputted and to hit the # key to run
 
	serout C.3,N9600_16,(254,1)
		pause 500
			serout C.3,N9600_16,(254,128,"EXP TIME -",254,139,#b7,254,141,":",254,142,#b6,254,144,":",254,145,#b5)
			serout C.3,N9600_16,(254,192,"INT TIME -",254,203,#b14,254,205,":",254,206,#b13,254,208,":",254,209,#b12)
			serout C.3,N9600_16,(254,148,"EXPOSURES -",254,160,#w14)
			serout C.3,N9600_16,(254,212,"HIT THE # KEY TO RUN")
				do
	  		gosub GKP
		loop until key_value = 12 ; 12 is the # key on keypad and will start the run sequencw when pressed
	goto RUNNING



RUNNING:
	pause 50
	let timer = b5
 	let b55 = b7
	let b54 = b6
	let b52 = b14
	let b51 = b13
					;shows the times incrementing up in realtime
	serout C.3,N9600_16,(254,1)	;and frames taken
	pause 30
		serout C.3,N9600_16,(254,128,"EXP TIME -",254,139,#b55,254,141,":",254,142,#b54,254,144,":",254,145,#timer)
		serout C.3,N9600_16,(254,192,"INT TIME -",254,203,#b52,254,205,":",254,206,#b51,254,208,":",254,209,#timer)
		serout C.3,N9600_16,(254,148,"EXPOSURES -",254,160,#w14)
		serout C.3,N9600_16,(254,212,"COUNTER -",254,222,#w15)

	pause 30
	high CAMERA
		settimer t1s_16
EXPO:
		if timer = 0 and b54 = 0 and b55 = 0 then goto expo1
	if timer = 0 and b54 = 0 then dec b55 let timer = 59 : let b54 = 59 endif
	if b55 < 10 then serout C.3,N9600_16,(254,139,"0",254,140,#b55) else
	serout C.3,N9600_16,(254,139,#b55) endif
	if timer = 0 then dec b54 let timer = 59 : endif
	if b54 < 10 then serout C.3,N9600_16,(254,142,"0",254,143,#b54) else
	serout C.3,N9600_16,(254,142,#b54) endif
	if timer < 10 then serout C.3,N9600_16,(254,145,"0",254,146,#timer) else
	serout C.3,N9600_16,(254,145,#timer) endif
	dec timer
	goto EXPO 
 
EXPO1:		;clears elapsed time, resets and increments counter for frames taken
	settimer off
	low CAMERA
		inc counter : serout C.3,N9600_16,(254,222,#w15) 
			if counter = frames then goto INIT
			let b55 = b7
			let b54 = b6
			let hrs = 0 
			let mins = 0
       			let timer = 0
       		serout C.3,N9600_16,(254,1)
	pause 30
		serout C.3,N9600_16,(254,128,"EXP TIME -",254,139,#b55,254,141,":",254,142,#b54,254,144,":",254,145,#b5)
		serout C.3,N9600_16,(254,192,"INT TIME -",254,203,#b52,254,205,":",254,206,#b51,254,208,":",254,209,#b12)
		serout C.3,N9600_16,(254,148,"EXPOSURES -",254,160,#w14)
		serout C.3,N9600_16,(254,212,"COUNTER -",254,222,#w15)	
	 settimer t1s_16
	 let timer = b12
 
 INTER: 
	if timer = 0 and b51 = 0 and b52 = 0 then goto inter1
 	if timer = 0 and b51 = 0 then dec b52 let timer = 59 : let b51 = 59 : endif
 	if b52 < 10 then serout C.3,N9600_16,(254,203,"0",254,204,#b52) else
	serout C.3,N9600_16,(254,203,#b52) endif
	if timer = 0 then dec b51 let timer = 59 : endif
	if b51 < 10 then serout C.3,N9600_16,(254,206,"0",254,207,#b51) else
	serout C.3,N9600_16,(254,206,#b51) endif
 	if timer < 10 then serout C.3,N9600_16,(254,209,"0",254,210,#timer) else
 	serout C.3,N9600_16,(254,209,#timer) endif
	dec timer
	goto INTER
 
 INTER1:        ;clears counters and loops back to EXPO if counter not = to frame
	settimer off
		
		let hrs1 = 0
		let mins1 = 0
		let timer1 = 0
	pause 30
		if counter < frames then goto RUNNING
		
		
GKP:				;keypad code
 	 Do
    		Gosub GTKP			' Wait until no key pressed
  			Loop Until key_value = 0
 	 Do
   		 Gosub GTKP			' Wait until key pressed
      			Loop Until key_value <> 0
  			If key_value = 11 Then
    			key_value = 0
  		endif
  	Return		
GTKP:	;Keypad scan coding
		key_pos = 0
		key_value = 0
	 	High ROW1 : gosub ScanCol : low ROW1
	 	High ROW2 : gosub ScanCol : low ROW2
	 	High ROW3 : gosub ScanCol : low ROW3 
 	 	High ROW4 : gosub ScanCol : low ROW4
	 	Return	 	
	 	ScanCol:
	 		if COL1 = 1 then : key_value = key_pos + 1 : endif
	 		if COL2 = 1 then : key_value = key_pos + 2 : endif
	 		if COL3 = 1 then : key_value = key_pos + 3 : endif
	 		key_pos = key_pos + 3   

   		return
Stewart
 
Top