Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:44 06 Feb 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Micromite Question

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1023
Posted: 05:10am 02 Feb 2026
Copy link to clipboard 
Print this post

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
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5660
Posted: 05:57am 02 Feb 2026
Copy link to clipboard 
Print this post

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
PicomiteVGA PETSCII ROBOTS
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1023
Posted: 12:50am 03 Feb 2026
Copy link to clipboard 
Print this post

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
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3340
Posted: 01:55am 03 Feb 2026
Copy link to clipboard 
Print this post

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
Geoff Graham - http://geoffg.net
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5660
Posted: 08:12am 03 Feb 2026
Copy link to clipboard 
Print this post

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
PicomiteVGA PETSCII ROBOTS
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1023
Posted: 08:55pm 03 Feb 2026
Copy link to clipboard 
Print this post

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
 
DaveJacko
Regular Member

Joined: 25/07/2019
Location: United Kingdom
Posts: 96
Posted: 10:01pm 03 Feb 2026
Copy link to clipboard 
Print this post

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 ?
Try swapping 2 and 3 over
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 1023
Posted: 11:06pm 03 Feb 2026
Copy link to clipboard 
Print this post

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
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4224
Posted: 11:41pm 03 Feb 2026
Copy link to clipboard 
Print this post

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

John
 
mozzie
Senior Member

Joined: 15/06/2020
Location: Australia
Posts: 201
Posted: 12:53am 04 Feb 2026
Copy link to clipboard 
Print this post

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
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1088
Posted: 04:36am 04 Feb 2026
Copy link to clipboard 
Print this post

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
F4 H7FotSF4xGT
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2970
Posted: 06:54am 04 Feb 2026
Copy link to clipboard 
Print this post

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
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 1041
Posted: 07:56am 04 Feb 2026
Copy link to clipboard 
Print this post

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

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

Frank
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5660
Posted: 08:30am 04 Feb 2026
Copy link to clipboard 
Print this post

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
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5660
Posted: 03:40pm 04 Feb 2026
Copy link to clipboard 
Print this post

@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
PicomiteVGA PETSCII ROBOTS
 
Print this page


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