Warning: Use of undefined constant PREG_PATTERN_VALID_LANGUAGE - assumed 'PREG_PATTERN_VALID_LANGUAGE' (this will throw an Error in a future version of PHP) in
/var/www/kucjica/emperors-wiki/inc/parser/xhtml.php on line
633
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in
/var/www/kucjica/emperors-wiki/inc/parser/xhtml.php on line
633
Warning: Use of undefined constant PREG_PATTERN_VALID_LANGUAGE - assumed 'PREG_PATTERN_VALID_LANGUAGE' (this will throw an Error in a future version of PHP) in
/var/www/kucjica/emperors-wiki/inc/parser/xhtml.php on line
633
Warning: preg_replace(): Delimiter must not be alphanumeric or backslash in
/var/www/kucjica/emperors-wiki/inc/parser/xhtml.php on line
633
arduino code
// Controlling a servo position using serial input
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int val; // variable to read the value from the analog pin
char t;
String str;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600);
}
void loop()
{
while (Serial.available()>0) {
char d = Serial.read();
if (d=='\n') {
char t[str.length()+1];
str.toCharArray(t, (sizeof(t)));
int intdata = atoi(t);
Serial.println(intdata);
myservo.write(intdata);
str = String();
}
else {
str.concat(d);
}
}
}
then in python:
import serial
ser=serial.Serial("/dev/ttyACM0", 9600)
ser.write("30\n")