-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79778c1
commit bf0b7ee
Showing
2 changed files
with
42 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
import serial | ||
import time | ||
|
||
# Open a serial port | ||
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1) | ||
ser.readline() | ||
|
||
up = True | ||
while True: | ||
data = ser.readline() | ||
if up: | ||
command = 'a' | ||
else: | ||
command = '0' | ||
ser.write(bytes(command, 'utf-8')) | ||
up = not up | ||
time.sleep(1) | ||
print(ser.readline()) | ||
|
||
# Length that corresponds each volume | ||
len_0mL = '1820' | ||
len_1mL = '1755' | ||
len_5mL = '1528' | ||
len_10mL = '1286' | ||
|
||
# Initialize | ||
ser.write(bytes(len_0mL, 'ascii')) | ||
time.sleep(5) | ||
print(ser.readline()) | ||
|
||
for _ in range(5): | ||
# Aspirate 5 mL | ||
ser.write(bytes(len_5mL, 'ascii')) | ||
time.sleep(5) | ||
print(ser.readline()) | ||
# Dispense liquid | ||
ser.write(bytes(len_0mL, 'ascii')) | ||
time.sleep(5) | ||
print(ser.readline()) | ||
ser.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,32 @@ | ||
#include <Servo.h> | ||
|
||
Servo myServo; | ||
|
||
int len0 = 1820; | ||
int len5 = 1522; | ||
int len10 = 1286; | ||
|
||
#define len0 (1820) | ||
#define PIN_SERVO (8) | ||
|
||
void setup() { | ||
void setup() | ||
{ | ||
Serial.begin(9600); | ||
Serial.println("Start!"); | ||
myServo.attach(PIN_SERVO); | ||
myServo.writeMicroseconds(len0); | ||
delay(5000); | ||
} | ||
|
||
void loop() { | ||
char key; | ||
if (Serial.available()) { | ||
key = Serial.read(); | ||
Serial.println(key); | ||
switch (key) { | ||
case 'a': | ||
myServo.writeMicroseconds(len10); | ||
break; | ||
case '5': | ||
myServo.writeMicroseconds(len5); | ||
break; | ||
case '0': | ||
myServo.writeMicroseconds(len0); | ||
break; | ||
|
||
void loop() | ||
{ | ||
if ( Serial.available() ) { | ||
String len_str = Serial.readString(); | ||
Serial.print("Received Value: "); | ||
Serial.println(len_str); | ||
int len = len_str.toInt(); | ||
if (len >= 1000 && len <= 2000) | ||
{ | ||
Serial.println("Valid value"); | ||
myServo.writeMicroseconds(len); | ||
} else { | ||
Serial.println("Invalid value"); | ||
} | ||
delay(1000); | ||
} | ||
} |