
!02 Envoyer et recevoir des données depuis/vers Arduino
Dans cet exemple nous allons contrôler une LED (rouge sur l'image) avec un potentiomètre - et tout ça avec un peu de logique dans un patch vvvv.
Pour schématiser: potar > vvvv (calcule: LED allumée ou éteinte?) > Arduino --> contrôle de LED.
Ca signifie que nous devons:
Assurez-vous de charger ce code dans la carte Arduino:
*
*/
int potPin = 5; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int val,serialGet = 0; // variable to store the value coming from the sensor/serial port (from vvvv)
int delaytime = 1; // delay time for the main loop
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT beginSerial(9600); // use the serial port to send/recieve values to/from the computer
}
void loop() {
val = analogRead(potPin); // read the value from the potentiometer
printInteger(val); // print the value to the serial port //linebreak serialWrite(10); serialWrite(13);
// read the serial port serialGet = serialRead();
// if the input is '-1' then there is no data
// at the input, otherwise store it
if (serialGet != -1) {
val = serialGet;
}
// if the stored value is 'H' turn the LED on
// if the stored value is 'L' turn the LED off
if (val == 'H') {
digitalWrite(ledPin, HIGH);
}
else if (val == 'L') {
digitalWrite(ledPin, LOW);
}
delay(delaytime);
}
Regardez comment connecter le potentiomètre:

Et le patch se trouve ici:

anonymous user login
~6min ago
~2h ago
~4h ago
~9h ago
~20h ago
~24h ago
~2d ago
~2d ago
~2d ago