init
This commit is contained in:
commit
18efc36800
161 changed files with 5008 additions and 0 deletions
39
scripts/arduino_control/Vibration.cs
Normal file
39
scripts/arduino_control/Vibration.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.IO.Ports;
|
||||
using Godot;
|
||||
|
||||
namespace MalagaJam18;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class Vibration : Node {
|
||||
private static SerialPort _serialPort;
|
||||
private static bool _initialized;
|
||||
|
||||
public static void Init(string port) {
|
||||
GD.Print(port);
|
||||
try {
|
||||
_serialPort = new SerialPort();
|
||||
_serialPort.PortName = port;
|
||||
_serialPort.BaudRate = 9600;
|
||||
_serialPort.Open();
|
||||
_initialized = true;
|
||||
}
|
||||
catch (Exception e) {
|
||||
GD.PrintErr(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendVibration() {
|
||||
if (!_initialized || !_serialPort.IsOpen)
|
||||
return;
|
||||
|
||||
_serialPort.WriteLine("#LED1ON");
|
||||
}
|
||||
|
||||
public static void UnSendVibration() {
|
||||
if (!_initialized || !_serialPort.IsOpen)
|
||||
return;
|
||||
|
||||
_serialPort.WriteLine("#LED1OF");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue