|
Forum Index : Microcontroller and PC projects : Micromite Question
| Author | Message | ||||
| OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 1023 |
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: NetherlandsPosts: 5660 |
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: AustraliaPosts: 1023 |
Volhout, unfortunately this is a very old Maximite project and according to the manual I will have to work another way. OA47 |
||||
| Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3340 |
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: NetherlandsPosts: 5660 |
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: AustraliaPosts: 1023 |
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 OA47 |
||||
| DaveJacko Regular Member Joined: 25/07/2019 Location: United KingdomPosts: 96 |
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: AustraliaPosts: 1023 |
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 KingdomPosts: 4224 |
LOC() doesn't seem necessary, just use INPUT$() or even INKEY$() John |
||||
| mozzie Senior Member Joined: 15/06/2020 Location: AustraliaPosts: 201 |
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: AustraliaPosts: 1088 |
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: AustraliaPosts: 2970 |
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: GermanyPosts: 1041 |
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: NetherlandsPosts: 5660 |
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: NetherlandsPosts: 5660 |
@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 |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |