Can't workout digitalRead() in processing using firmata

Hi,
I am trying to connect my Arduino uno through firmata into processing. I have uploaded the standardFirmata code to my Arduino uno, added the Arduino/firmata lib to processing. Using this code I have established a working connection between Processing and Arduino IDE. The LED is flashing as it should be but somehow, the digitalRead does not read 1 when the LED is on. The console is continuously printing 0. What should I do? Thanks for help, I am very new to all of this :slight_smile:

import processing.serial.*;
import cc.arduino.*;

Arduino arduino;


int led = 2;

void setup() {
  size(500,500);
  
  println(Arduino.list());
  
  arduino = new Arduino(this, Arduino.list()[2], 57600);
  
  arduino.pinMode(led, Arduino.OUTPUT);
}

void draw(){
  
  arduino.digitalWrite(led, Arduino.HIGH);
  int val = arduino.digitalRead(led);
  println(val);
  delay(1000);
  
  
  arduino.digitalWrite(led, Arduino.LOW);
  rect(250, 250, 100, 100);
  val = arduino.digitalRead(led);
  println("OO");
  delay(1000);
}

Why read from the pin?
You know what value you last wrote to the LED pin.

For buttons, I simplified the code to the bare minimum but the original idea is: When I press button, the LED turn on, read value on the pin button, turn led pin HIGH and in processing draw AN ellipse.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.