Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : Micromite Question

Posted: 05:10am
02 Feb 2026
Copy link to clipboard
OA47
Guru


Is there a procedure to start a LED flashing (Pulse a PIN) when the program is at an INPUT prompt and restore the LED when the INPUT prompt is satisfied?

OA47
 
Posted: 05:57am
02 Feb 2026
Copy link to clipboard
Volhout
Guru

Hi oa,

Write a small SUB. that toggles the  LED pin.

Just before the input statement set a time interrupt with SETTICK pointing to that SUB.
After the input, use SETTICK,0,0 to stop the blinking.
Then a PIN() = x to restore the old led state.

Volhout
Edited 2026-02-02 15:59 by Volhout
 
Posted: 12:50am
03 Feb 2026
Copy link to clipboard
OA47
Guru


Volhout, unfortunately this is a very old Maximite project and according to the manual

  Quote  Interrupts can occur at any time but they are disabled during the execution of INPUT statements.


I will have to work another way.

OA47
 
Posted: 01:55am
03 Feb 2026
Copy link to clipboard
Geoffg
Guru


The best way around this issue is to use non blocking INPUT$() and some logic to get the input data, then you could do as Volhout suggested.  I did have a function to do that but I'm overseas and cannot find it, perhaps someone else can help.

Geoff
Edited 2026-02-03 11:56 by Geoffg
 
Posted: 08:12am
03 Feb 2026
Copy link to clipboard
Volhout
Guru

Hi OA47,

This could do it, the LED blinks until <ENTER> is typed on the keyboard.
'blink led while waiting for input

'prepare LED for blinking
SetPin 2,dout   'LED connected to pin 2
Pin(2)=1        'LED ON


'input routine ----------------------------------------------------------

SetTick 200,blink 'blink period = 2*200ms = 400ms
answer$=""
Do
 If Loc(0) Then                 'are there characters in input buffer
   answer$=answer$+Input$(1,0)  'read one character from input buffer
 EndIf
Loop Until Right$(answer$,1)=Chr$(13) 'did we hit return ?
SetTick 0,0

'end input routine ------------------------------------------------------

Print answer$
Pin(2)=1        'Resore LED condition

End


Sub blink
 Pin(2)=1-Pin(2) 'toggle LED pin
End Sub


Tested on micromite MKII

Volhout
Edited 2026-02-03 18:26 by Volhout
 
Posted: 08:55pm
03 Feb 2026
Copy link to clipboard
OA47
Guru


Volhout,

It looks like th version 4 MBasic does not use Loc() for keyboard

If Loc(0) Then
ERROR: Invalid File Number


From the handbook
  Quote  LOC( [#]fnbr )
For a file opened as RANDOM this will return the current position of the
read/write pointer in the file.  Note that the first byte in a file is
numbered 1.  See Appendix I for more details of random file access.
For a serial port this will return the number of bytes received and
waiting in the receive buffer to be read.  
The ‘#’ character is optional.


OA47
 
Posted: 10:01pm
03 Feb 2026
Copy link to clipboard
DaveJacko
Regular Member

I might have a better idea ! (rare occurence)
how about using PWM to flash the led?
maybe adds 3 lines of code

Marks out of 10 anyone ?
 
Posted: 11:06pm
03 Feb 2026
Copy link to clipboard
OA47
Guru


DaveJacko, that is a great idea but unfortunately I only have one PWM output and currently that is wired for sound. In this situation sorry no marks out of 10.

OA47
 
Posted: 11:41pm
03 Feb 2026
Copy link to clipboard
JohnS
Guru

LOC() doesn't seem necessary, just use INPUT$() or even INKEY$()

John
 
Posted: 12:53am
04 Feb 2026
Copy link to clipboard
mozzie
Senior Member

G'day OA47,
In the distant past I had a similar need, don't have access to the original but it was something like this:


' prog to flash LED waiting for input
' for MMite V4.05

option default integer
setpin 16,dout

a$=inkey$     'clear input buffer
a$=""         'clear input string

pin(16)=1     ' set led on

do
 A$=A$+inkey$
 b=b+1:pin(16)=(b/16) and 1
 pause 10
loop until right$(A$,1)=CHR$(13)

pin(16)=0     'set LED off

print A$

end


It's good to go back to the early MMbasic from time to time to be reminded just how far it has come and how much power we now have at our finger tips  

You could also use the ON KEY interrupt but this is simpler.

Another option is a flashing led (eg Jaycar ZD0245)

Hope this helps and good luck.

Regards,
Lyle.
Edited 2026-02-04 11:01 by mozzie
 
Posted: 04:36am
04 Feb 2026
Copy link to clipboard
disco4now
Guru


This might give some help. Was initially for MMBasic 4.5
Uses  Inkey$, concatenating the keypresses until Enter is received.
  ' wait on key press
   Do: key = Asc(Inkey$): Loop Until key

LINEEDIT on FotS
 
Posted: 06:54am
04 Feb 2026
Copy link to clipboard
phil99
Guru


Expanding Disco4now's code to include flashing LED:-
> SetPin 1,dout
> t=timer :Do: key = Asc(Inkey$) :if timer-t>500 then :pin(1)=not pin(1) :t=timer :endif :Loop Until key


If V4.5 doesn't like reading back a DOUT pin you will need to add a variable.

LED = Not LED : pin(1) = LED
 
Posted: 07:56am
04 Feb 2026
Copy link to clipboard
Frank N. Furter
Guru

Stupid idea: Why not use a self-blinking LED?

https://cdn-reichelt.de/documents/datenblatt/A500/LEDBL5MM~KIN.pdf

Frank
 
Posted: 08:30am
04 Feb 2026
Copy link to clipboard
Volhout
Guru

Hi OA47,

I must have mis-read your question. I was under the impression you used a micromite (thread title)... but it was a maximite 1.

OK, this code is tested on a CG-COLORMAX-II running MMBasic 4.5C. On the CG-ColorMax-II pin(0) is the power LED. You can of coarse change the LED_pin to any pin you like.
CG stands for Circuit Gizmo (I assume).

'blinking power led during input
'maximite MMBasic 4.5C

'------------------- defines -----------------

'define the LED status
LED_pin=0           'LED is connected to pin 0
LED=1               '1=on,0=off
Pin(LED_pin)=LED    'power led on
Blinkspeed = 100    'ON time and OFF time


'--------------------- main ------------------

' this is what you put in your main software
a$ = get_blink$()
' an alternative input statement

Print a$
EndIf


' ------------- subs and functions -----------

' returns with the string, similar to INPUT a$
Function get_blink$()
 SetTick Blinkspeed,Blink_the_LED,4        'start blinking
 Do
   get_blink$ = get_blink$ + Inkey$        'get characters
 Loop Until Right$(get_blink$,1)=Chr$(13)  'until <ENTER>
 SetTick 0,0,4 : LED=1 : Pin(LED_pin)=LED  'stop blink
End Function

' turn the LED on and off
Sub Blink_the_LED
 LED = 1 - LED
 Pin(LED_pin) = LED
End Sub


The essential change is that in your code you have to replace the
INPUT a$

with
a$ = get_blink$()


Volhout

P.S. after pulling out the CG-ColorMax-II and powering it ON, I realized how much perfection was put in the Maximite. The nice colorfull MaxiMite logo that welcomes you. Very different from the cool "PICOMITE V6.02.00, Copyright...." text. The MaxiMite feels more mature, polished.
P.P.S. The MaximMIte was in storage since the first "MMBasic Programming Contest", 5 or 6 years ago. I turned it ON, and the unit immediately showed the correct time and date (except daylight saving).... another plus. Good battery.
Edited 2026-02-04 19:01 by Volhout
 
Posted: 03:40pm
04 Feb 2026
Copy link to clipboard
Volhout
Guru

@Geoff,

Since my motoric memory was trained on PicoMite I cannot fail noting that between PicoMite and CMM1 the F1 and F2 functions are swapped when on commandline.

CMM1 : commandline F1 = run, F2 = save
CMM1 : in editor   F1 = save, F2 = run
PICO : F1 = save, F2 = run both commandline and in editor

Volhout
 
Posted: 05:45am
06 Feb 2026
Copy link to clipboard
OA47
Guru


I have to put this one on the backburner as I have just realised that I have only 4 interrupts to use in this version of basic and they are all spoken for. It looks like a change in hardware is the most acceptable path at this stage. Thankyou all for your contributions.

OA47
 
Posted: 07:34am
06 Feb 2026
Copy link to clipboard
mozzie
Senior Member

G'day OA47,
If a lack of free interrupts is the only issue, perhaps the code I posted earlier is still an option.

Short Version:

setpin 16,dout

a$=inkey$     'clear input buffer
a$=""         'clear input string
b=15          'set LED on at start

do
 A$=A$+inkey$
 b=b+1:pin(16)=(b/16) and 1
 pause 10
loop until right$(A$,1)=CHR$(13)
pin(16)=0     'set LED off

print A$

Still have not found the complete original but this was close:

SetPin 16,dout

a$=Inkey$     'clear input buffer
a$=""         'clear input string
b=15          'set flash on at start
c=16          'slow flash rate to start

Do
 A$=A$+Inkey$
 Text 0,0,A$
 b=b+1:Pin(16)=(b/c) And 1 'flash rate
 If b>512 Then c=8 Else c=16
 If Len(a$)>olen Then olen=Len(a$):b=b And &h1f
 If Right$(a$,1)=Chr$(&h1b) Or b>1000 Then A$="":Exit Do
 Pause 10
Loop Until Right$(A$,1)=Chr$(13)

Pin(16)=0     'set LED off

Print A$

This starts off slow flashing for 5 secs, goes fast for 5 secs unless a key is pressed or it will return with a blank string.

Might be useful for someone.

Regards,
Lyle.
 


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026