Hello,
I would like to know how to drive the LED through the tkinter from the PC.
It may be necessary to write some script into the main.py board and then run it through the script in the PC.
Everything works, but when we turn on LED 1 and turn on LED 2, only the LED will remain on 2. When sending data to the board, the LED will flash and I do not want to.
my script for PC:
import pyboard
import time
from tkinter import *
pyb = pyboard.Pyboard('/dev/tty.usbmodem1432')
def led1_on():
pyb.enter_raw_repl()
pyb.exec('import pyb')
pyb.exec('pyb.LED(1).on()')
pyb.exit_raw_repl()
def led1_off():
pyb.enter_raw_repl()
pyb.exec('import pyb')
pyb.exec('pyb.LED(1).off()')
pyb.exit_raw_repl()
def led2_on():
pyb.enter_raw_repl()
pyb.exec('import pyb')
pyb.exec('pyb.LED(2).on()')
pyb.exit_raw_repl()
def led2_off():
# LED2 = pyb.LED(2).off()
pyb.enter_raw_repl()
pyb.exec('import pyb')
pyb.exec('pyb.LED(2).off()')
pyb.exit_raw_repl()
led_control_window= Tk()
led_control_window.geometry('270x200+200+200')
btn1=Button(led_control_window,text="LED1 ON",
command=led1_on).place(x = 60, y = 40,
width=70, height=40)
btn2=Button(led_control_window,text="LED1 OFF",
command=led1_off).place(x = 60, y = 90,
width=70, height=40)
btn3=Button(led_control_window,text="LED2 ON",
command=led2_on).place(x = 140, y = 40,
width=70, height=40)
btn4=Button(led_control_window,text="LED2 OFF",
command=led2_off).place(x = 140, y = 90,
width=70, height=40)
LED from PC
Re: LED from PC
If you're using the raw REPL to send commands then that will be the problem.
Everytime you enter the raw repl, the board goes through a soft-reset cycle, which will turn all of the LEDs off.
I wrote a json-ipc library https://github.com/dhylands/json-ipc which you can run on the MicroPython board and send commands to it in the form of JSON messages.
Everytime you enter the raw repl, the board goes through a soft-reset cycle, which will turn all of the LEDs off.
I wrote a json-ipc library https://github.com/dhylands/json-ipc which you can run on the MicroPython board and send commands to it in the form of JSON messages.