arduino stuffs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
extends Node

var input := Vector2.ZERO

var fast := false

onready var lb = $Label


func _physics_process(_delta):
	var inp := get_input()
	if inp != input:
		input = inp
		lb.text = str(input)
		SerialIO.write("H%s,%s" % [input.x, input.y])


func _ready():
	yield(get_tree(), "idle_frame")
	SerialIO.write("H0,0")  #stop
	lb.text = str(input)


func get_input() -> Vector2:
	if Input.is_action_just_pressed("sped"):
		fast = !fast
	var x := Input.get_action_strength("leftpaddle")
	var y := Input.get_action_strength("rightpaddle")
	var multiplier := 100 if fast else 50
	var v := Vector2(x, y) * multiplier
	# if button is pressed, reverse, if no paddle input, move slow
	if Input.is_action_pressed("lb"):
		v.x = -v.x if v.x else -multiplier / 4.0
	if Input.is_action_pressed("rb"):
		v.y = -v.y if v.y else -multiplier / 4.0
	return (v).round()