gsd 7 months ago
parent
commit
d26e3c3300
  1. 4
      pipboyIO/pipboyIO.ino
  2. 12
      pipboyIO/serialTest.py

4
pipboyIO/pipboyIO.ino

@ -1,5 +1,5 @@
const int input[] = {36, 39, 34 ,35 ,32 ,33 ,25 ,26};
int inputValue[] = {0, 0, 0, 0, 0, 0, 0, 0};
long inputValue[] = {0, 0, 0, 0, 0, 0, 0, 0};
const int numPins = sizeof(input) / sizeof(input[0]);
#define RXD2 (16)
@ -24,7 +24,7 @@ void values2uart() {
void loop() {
for (int i = 0; i < numPins; i++) {
inputValue[i] = analogRead(input[i]) / 100;
inputValue[i] = map(analogRead(input[i]), 0, 4096, 0, 100);
}
values2uart();

12
pipboyIO/serialTest.py

@ -11,6 +11,7 @@ class Const:
34:"Крутилка 4",
26:"Кнопки"
}
FULL = 100
class Pin:
def __init__(self, id, initValue):
@ -21,6 +22,8 @@ class Pin:
def updateValue(self, value):
if self.value == value:
return (self, 0)
elif abs(self.value - value) == 1:
return (self, 0)
else:
self.value = value
return (self, value)
@ -33,8 +36,11 @@ class SerialListener:
def reInit(self):
if self.ser:
self.ser.close()
self.ser.open()
try:
self.ser.close()
self.ser.open()
except:
pass
def listen(self):
while True:
@ -47,6 +53,8 @@ class SerialListener:
self.pins[pin] = Pin(pin, value)
else:
yield self.pins[pin].updateValue(value)
except ValueError:
continue
except KeyboardInterrupt:
print("exit from main loop")
sys.exit(0)

Loading…
Cancel
Save