モーターを
Raspberry Pi側で
Pythonで
import serial
import sys
if len(sys.argv) < 1:
sys.exit()
width = int(sys.argv[1])
if width == 0:
sys.exit()
s = serial.Serial("/dev/ttyS0", 115200)
s.write(width.to_bytes(2, 'little'))
unsigned long ts;
unsigned int width = 1500;
char bytes[2];
void setup() {
Serial.begin(115200);
ts = micros();
DDRB = DDRB | B00100000; // pin 13
}
void loop() {
unsigned long t = micros() - ts;
if (Serial.available() > 1) {
Serial.readBytes(bytes, 2);
width = (bytes[1] << 8) | (bytes[0] & 0xff);
}
if (t <= width) {
PORTB = PORTB | B00100000;
}
else {
PORTB = B00000000;
}
if (t >= 20000) {
ts = micros();
}
}