# Processing quiz

**URL:** <https://discourse.processing.org/t/processing-quiz/32784>\
**Category:** Electronics (Arduino, etc.)\
**Tags:** homework\
**Created:** [October 12, 2021, 8:54pm UTC](https://discourse.processing.org/t/processing-quiz/32784 "2021-10-12T20:54:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rayenblue](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Rayenblue](https://discourse.processing.org/u/Rayenblue)\
**Post date:** [October 12, 2021, 8:54pm UTC](https://discourse.processing.org/t/processing-quiz/32784/1 "2021-10-12T20:54:34Z")

</div>

Hello Everyone !

I have a project with my university, i have to create à quizz which you can chose the answer by using Arduino button. For the moment i can’t send the stat of my button to processing and i dont know why.

Arduino :

```auto
int bouton = 4;

void setup() {

  pinMode(bouton, INPUT); // Set pin 0 as an input
  Serial.begin(9600); // Start serial communication at 9600 bps
}

void loop() {
  if (digitalRead(bouton) == HIGH) { // If switch is ON,
    Serial.write(1);
    Serial.println("oui"); // send 1 to Processing
  } else { // If the switch is not ON,
    Serial.write(0);
    Serial.println("non"); // send 0 to Processing
  }
  Serial.println(bouton);
  delay(100); 
} 

```

Processing :

```auto
import processing.serial.*;
int val;
Serial myPort; // Create object from Serial class

void setup()
{

  String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
  myPort = new Serial(this, portName, 9600);
  printArray(Serial.list());
  String myPortName = Serial.list()[0];
}

void draw()
{
  if ( myPort.available() > 0) {
    val = myPort.read();
  }
  if ( val == 1) {
    fill(127, 0, 0);
  } else {
    fill(255, 200, 200);
  }
}

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 13, 2021, 9:39pm UTC](https://discourse.processing.org/t/processing-quiz/32784/2 "2021-10-13T21:39:10Z")

</div>

Hello,

What are you `fill()` ing?

> **[Reference](https://processing.org/reference/fill_.html)**
>
> Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), all subsequent shapes will be filled with orange. This color is either specified in terms of the RGB or HSB color …

There are lots of resources and examples here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts…

`:)`

---

<div class="post-metadata">

**Author:** ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)\
**Post date:** [October 14, 2021, 5:22pm UTC](https://discourse.processing.org/t/processing-quiz/32784/3 "2021-10-14T17:22:13Z")

</div>

Hi @Rayenblue, I can see that you started with the Processing example ‘SimpleRead’. This does work, I’ve just tried it, but there are ways that it can be messed up. You’ve added some println to see if the Arduino is working. There’s a conflict here because those prints are also going to Processing and confusing things. You want only the 1 and 0 to go to Processing. Once you’ve seen the Ard prog is working (you’re using the serial monitor?), please remove them all. (We’ll talk about how to have both later.)

Are you sure your Processing is connecting to the port? Don’t have the Serial Monitor running when you start your Processing sketch. Do you have the com port name correct? Suggest you use this line  
myPort = new Serial(this, “COM13”, 9600);  
instead of the serial.list[] method. Change the port name to same as in the Ard IDE.

See if those 2 fix it, let us know…

---

<div class="post-metadata">

**Author:** ![Rayenblue](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Rayenblue](https://discourse.processing.org/u/Rayenblue)\
**Post date:** [October 15, 2021, 7:41pm UTC](https://discourse.processing.org/t/processing-quiz/32784/4 "2021-10-15T19:41:48Z")

</div>

Thank you for your replay !

But unfortunely that didn’t work , i removed Serial.print and try your methode on Process, can you explain me what do you mean when your say " Are you sure your Processing is connecting to the port?", becauce I sucessed to send text .

---

<div class="post-metadata">

**Author:** ![Rayenblue](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Rayenblue](https://discourse.processing.org/u/Rayenblue)\
**Post date:** [October 15, 2021, 7:57pm UTC](https://discourse.processing.org/t/processing-quiz/32784/5 "2021-10-15T19:57:47Z")

</div>

![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a97f56fdb4b211cc11d0e1de643cf4a97701fa8b.png)

---

<div class="post-metadata">

**Author:** ![Rayenblue](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Rayenblue](https://discourse.processing.org/u/Rayenblue)\
**Post date:** [October 15, 2021, 7:59pm UTC](https://discourse.processing.org/t/processing-quiz/32784/6 "2021-10-15T19:59:03Z")

</div>

I use your command “myPort = new Serial(this, “COM3”, 9600);” .

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 15, 2021, 9:23pm UTC](https://discourse.processing.org/t/processing-quiz/32784/7 "2021-10-15T21:23:05Z")

</div>

Hello @Rayenblue,

If you are in fact connecting you need a shape to `fill()` !  
Your code is missing one.

You could also add:

```auto
val = myPort.read();
println(val);

```

This will show all the extra characters you are sending; you are sending `'0'` or else… the else is all the extra characters from your `Serial.print()` statements.

What does this (below) display on your console?

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/58d04bfa733a12fb42b0bd53045b7c0c797382ed.png)

My Arduino is on “COM6” so I would use:

```auto
  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);

```

Have fun!

References:

- [https://processing.org/reference/libraries/serial/index.html](https://processing.org/reference/libraries/serial/index.html)
- [https://github.com/processing/processing/blob/master/java/libraries/serial/examples/SimpleRead/SimpleRead.pde](https://github.com/processing/processing/blob/master/java/libraries/serial/examples/SimpleRead/SimpleRead.pde)
- [https://processing.org/tutorials/electronics](https://processing.org/tutorials/electronics)

`:)`

---

<div class="post-metadata">

**Author:** ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)\
**Post date:** [October 16, 2021, 4:47pm UTC](https://discourse.processing.org/t/processing-quiz/32784/8 "2021-10-16T16:47:21Z")

</div>

@Rayenblue Yes, from your IDE image COM3 is the correct name. I would use it direct. The list()[] method works but the list can change if any other devices are added/removed. Is your Arduino a real one? The cheap Chinese ones take a different COMn number in different USB sockets.

Have you added the print as @glv said? Is anything printing?

The Ard sketch only sends every 100 mS. If you press and release the button quickly it may happen within 100 mS and be ignored. I think for the quiz you will find it too slow to react. The 100 delay at the end of the Ard sketch is too big. Suggest you change it to 40 mS. You could go less but it must be greater than the loop delay of the Processing, and we don’t know that yet. Once you get it working I think we should alter the Ard sketch to send on change, and on a slow frequency.

---

<div class="post-metadata">

**Author:** ![Rayenblue](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Rayenblue](https://discourse.processing.org/u/Rayenblue)\
**Post date:** [October 17, 2021, 1:22pm UTC](https://discourse.processing.org/t/processing-quiz/32784/10 "2021-10-17T13:22:13Z")

</div>

![3](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/868456ba98606f424de29dd79d074475ce05e44c.png)

Awesome ! Now i am sure that arduino is well connecte but my condition is still not working.

---

<div class="post-metadata">

**Author:** ![Rayenblue](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Rayenblue](https://discourse.processing.org/u/Rayenblue)\
**Post date:** [October 17, 2021, 1:24pm UTC](https://discourse.processing.org/t/processing-quiz/32784/11 "2021-10-17T13:24:17Z")

</div>

Thank you @RicharDL, my arduino is not a fake and my COM is the good , i add @glv code ( thank you 🤩 🤩 by the way) and it show me values. 40 ms was a very good call , thank you again.

 ![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2731c0a4256407617b340212c29e316845999da5.png)

---

<div class="post-metadata">

**Author:** ![Rayenblue](https://avatars.discourse-cdn.com/v4/letter/r/3be4f8/32.png) [@Rayenblue](https://discourse.processing.org/u/Rayenblue)\
**Post date:** [October 17, 2021, 2:32pm UTC](https://discourse.processing.org/t/processing-quiz/32784/12 "2021-10-17T14:32:58Z")

</div>

IT’S ALIVE !!! IT’S ALIVE !!!

Thank you ,it’s work know !

Now the real challenge can begin

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [October 17, 2021, 3:10pm UTC](https://discourse.processing.org/t/processing-quiz/32784/13 "2021-10-17T15:10:26Z")

</div>

> [@Rayenblue](#):
>
> Now the real challenge can begin

Have fun!

There are lots of topics related to serial communication.  
It gets easier…

If you need further assistance ask.

`:)`
