Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | mineralman |
Hello everyone,
I use this solutionand this is the project code
extends Node2D
const SERCOMM = preload(“res://bin/GDsercomm.gdns”)
onready var PORT = SERCOMM.new()
onready var val = 3
onready var port_list = PORT.list_ports()
onready var RecevedMessages = $RecevedMessages
onready var SendMessage = $SendMessage
func _ready():
set_physics_process(false)
yield(get_tree(),"idle_frame")
open_port('COM5');
func _physics_process(delta):
if PORT.get_available()>0:
print(val)
RecevedMessages.add_text(PORT.read())
pass
func open_port(port_name, baudrate=9600):
if port_name!=null:
PORT.open(port_name, baudrate,1000)
set_physics_process(true)
func _input(event):
if event is InputEventKey and event.pressed:
if event.scancode == KEY_RIGHT:
PORT.write(val)
func _on_Button_pressed():
PORT.write(SendMessage.text)
SendMessage.text = ""
to connect godot to an arduino, but when I try to send a single number like number (3) to godot I get a multitude of numbers like this (33333333333333333) , i heard that the issue is about the numbers of frames per second and that godot checks and duplicate the received message every frame, i also found tha it is possible to avoid duplication in ( func _input(event): )
with something similar to this
https://forum.godotengine.org/5707/how-to-avoid-key-typing-repetition
But in my case the reception of the message is managed by the( func _physics_process(delta) so is there a way do something similar in this function to avoid duplication?
Or is there a nother solution?
Thank you.