mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
more example moving
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
// Read data from the serial and turn ON or OFF a light depending on the value
|
||||
char val; // Data received from the serial port
|
||||
int ledPin = 0; // Set the pin to digital I/O 0
|
||||
|
||||
void setup() {
|
||||
pinMode(ledPin, OUTPUT); // Set pin as OUTPUT
|
||||
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
|
||||
}
|
||||
if (val == 'H') { // If H was received
|
||||
digitalWrite(ledPin, HIGH); // turn the LED on
|
||||
} else {
|
||||
digitalWrite(ledPin, LOW); // Otherwise turn it OFF
|
||||
}
|
||||
delay(100); // Wait 100 milliseconds for next reading
|
||||
}
|
||||
Reference in New Issue
Block a user