afficher le signal cherché pendant 2 second

a marqué ce sujet comme résolu.

bonjour

je cherche a afficher un signal sur procssing 2.2.1 lié avec l’ arduino pendant juste deux secondes

import processing.serial.*;

Serial myPort; // The serial port

int xPos = 1; // horizontal position of the graph

float height_old = 0;

float height_new = 0;

float inByte = 0;

void setup () {

// set the window size:

size(512,512);

// List all the available serial ports

println(Serial.list());

// Open whatever port is the one you’re using.

myPort = new Serial(this, Serial.list()[0], 9600);

// don’t generate a serialEvent() unless you get a newline character:

myPort.bufferUntil(’\n’);

// set inital background:

background(0xff);

}

void draw () {

// everything happens in the serialEvent()

}

void serialEvent (Serial myPort) {

// get the ASCII string:

String inString = myPort.readStringUntil(’\n’);

if (inString != null) {

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// trim off any whitespace:

inString = trim(inString);

// If leads off detection is true notify with blue line

if (inString.equals("!")) {

  stroke(0, 0, 0xff); //Set stroke to blue ( R, G, B)

  inByte = 512;  // middle of the ADC range (Flat Line)

}

// If the data is good let it through

else {

  stroke(0xff, 0, 0); //Set stroke to red ( R, G, B)

  inByte = float(inString);

 }

 //Map and draw the line for new data point

 inByte = map(inByte, 0, 1023, 0, height);

 height_new = height - inByte;

 line(xPos - 1, height_old, xPos, height_new);

 height_old = height_new;

  // at the edge of the screen, go back to the beginning:

  if (xPos >= width) {

    xPos = 0;

    background(0xff);

  }

  else {

    // increment the horizontal position:

    xPos++;

  }

}

}

Bonjour AminToukebri et bienvenue sur ZdS !

Afin de t’aider au mieux, j’ai déplacer ton sujet dans la section appropriée (la section vos projets à pour but de présenter le projet ;) )

Aussi, utilise les balises de code pour présenter ton code source. Sinon, celui-ci est presque ilisible.

Tu peux faire cela en suivant cette syntaxe :

1
2
3
~~~~arduino
// Place ton code ici
~~~~

Ce qui donne avec un vrai code :

1
2
3
4
5
6
Serial port;

int loop() {
    int cmp = 10;
    cmp++;
}

En dernier point, ton message n’est pas très compréhensible. On ne comprend pas quel est le problème. Tu cherches à afficher un signal, ok. Processing et arduino, ok. Mais où bloques-tu ? Qu’as-tu commes comportement ? Aide nous à t’aider.

Pour corriger tous ces points, tu peux éditer ton message grace à une option dans l’entête de celui-ci.

Bonne journée.

+3 -0
Connectez-vous pour pouvoir poster un message.
Connexion

Pas encore membre ?

Créez un compte en une minute pour profiter pleinement de toutes les fonctionnalités de Zeste de Savoir. Ici, tout est gratuit et sans publicité.
Créer un compte