mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
blue book examples
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
// Read data from the serial port and set the position of a servomotor
|
||||
// according to the value
|
||||
Servo myservo; // Create servo object to control a servo
|
||||
|
||||
int servoPin = 0; // Connect yellow servo wire to digital I/O pin 0
|
||||
int val = 0; // Data received from the serial port
|
||||
|
||||
void setup() {
|
||||
myservo.attach(servoPin); // Attach the servo to the PWM pin
|
||||
Serial.begin(9600); // Start serial communication at 9600 bps
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available()) { // If data is available to read,
|
||||
val = Serial.read(); // read it and store it in val
|
||||
}
|
||||
myservo.write(val); // Set the servo position
|
||||
delay(15); // Wait for the servo to get there
|
||||
}
|
||||
Reference in New Issue
Block a user