Commit 4e6f1d4e authored by Nelso Jost's avatar Nelso Jost

ADD: simple firmware for handling cinta-joystick data

parent 9b4fa8fb
......@@ -4,3 +4,4 @@ firmware/Makefile
firmware/.scripts
build
.build
*.log
[joystickrespirometro]
serial_port = /dev/ttyACM0
baud_rate = 9600
serial_port = /dev/ttyUSB0
baud_rate = 115200
[maze]
cycle = //\\//\\
......
int r, s, v;
void setup()
{
Serial.begin(115200);
pinMode(2, INPUT);
}
void loop()
{
r = analogRead(A1); // retificado
s = digitalRead(2); // bit sinal
v = (1 - 2*s) * r + 1023;
// if (s == 0)
// v = r + 500;
// else
// v = -r + 500;
Serial.println(v);
}
......@@ -161,19 +161,11 @@ class PlayerSprite(Sprite):
def handle_joystick(self):
self.app.joystick_respirometro.update()
if self.app.joystick_respirometro.inhaling():
self.accel.j = self.vel.j = -1
self.running = True
elif self.app.joystick_respirometro.exhaling():
self.accel.j = self.vel.j = 1
self.running = True
else:
self.running = False
self.y = self.app.joystick_respirometro.read - 1000
class JoystickRespirometro:
AMPLITUDE = 2
AMPLITUDE = 1
def __init__(self, serial_port, baud_rate):
self._state = 0
......@@ -182,11 +174,15 @@ class JoystickRespirometro:
try:
self._sercon = serial.Serial(serial_port, baud_rate, timeout=1)
self._enabled = True
self.timer = Timer(dt=0.2, callback=self.refresh)
self.timer = Timer(dt=0.1, callback=self.refresh)
except Exception as e:
print('[SerialOpenError] {}: {}'.format(e.__class__.__name__, e))
self._enabled = False
@property
def read(self):
return self._last_read
@property
def enabled(self):
return self._enabled
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment